Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.

Kleo-Network/connect-backend

Repository files navigation

how to start server

pipenv shell
python3 run.py

The MIT License

Flask Boilerplate to quickly get started with production grade flask application with some additional packages and configuration prebuilt.

You can find an in-depth article on this implementation here.

Contributing

We encourage you to contribute to Flask Boilerplate! Please check out the Contributing guidelines about how to proceed.

Getting Started

Prerequisites

  • Python 3.11.3 or higher
  • Up and running Redis client

Project setup

# clone the repo
$ git clone https://github.com/idris-rampurawala/flask-boilerplate.git
# move to the project folder
$ cd flask-boilerplate

If you want to install redis via docker

$ docker run -d --name="flask-boilerplate-redis" -p 6379:6379 redis

Creating virtual environment

  • Install pipenv a global python project pip install pipenv
  • Create a virtual environment for this project
# creating pipenv environment for python 3
$ pipenv --three
# activating the pipenv environment
$ pipenv shell
# install all dependencies (include -d for installing dev dependencies)
$ pipenv install -d

# if you have multiple python 3 versions installed then
$ pipenv install -d --python 3.11

Configuration

  • There are 3 configurations development, staging and production in config.py. Default is development
  • Create a .env file from .env.example and set appropriate environment variables before running the project

Running app

  • Run flask app python run.py
  • Logs would be generated under log folder

Running celery workers

  • Run redis locally before running celery worker
  • Celery worker can be started with following command
# run following command in a separate terminal
$ celery -A celery_worker.celery worker --loglevel='INFO'  
# (append `--pool=solo` for windows)

Preconfigured Packages

Includes preconfigured packages to kick start flask app by just setting appropriate configuration.

Package Usage
celery Running background tasks
redis A Python Redis client for caching
flask-cors Configuring CORS
python-dotenv Reads the key-value pair from .env file and adds them to environment variable.
marshmallow A package for creating Schema, serialization, deserialization
webargs A Python library for parsing and validating HTTP request objects

autopep8 & flake8 as dev packages for linting and formatting

Test

Test if this app has been installed correctly and it is working via following curl commands (or use in Postman)

  • Check if the app is running via status API
$ curl --location --request GET 'http://localhost:5000/status'
  • Check if core app API and celery task is working via
$ curl --location --request GET 'http://localhost:5000/api/v1/core/test'
  • Check if authorization is working via (change API Key as per you .env)
$ curl --location --request GET 'http://localhost:5000/api/v1/core/restricted' --header 'x-api-key: 436236939443955C11494D448451F'

Contract Document

Base path for all APIs: https://api.kleo.network/

User APIs

  1. Get user details from solana address[signup/login]

Description:

path api/v1/core/user/create-user
Type POST
Description To fetch user details from the DB
Header No header
Path Variable No

Body Param:

No Param name type Description Required
1 Address String Solana address of the user True
2 signup Boolean Flag for the user creation for signup False

Example:

1. Sign up {

“address”: “2aNXZ2gicvGkF7CyzBK8qguA6ycoXMcgw7usvLBRZiFK”

“signup”: true

}

2. Login {

“address”: “DRerVGgicvGkF7BRfyK8qguA6ycoXMcgw7usvLBhdEDC”

}

Response:

No Status Code Response
1. 200 {

address: “2aNXZ2gicvGkF7CyzBK8qguA6ycoXMcgw7usvLBRZiFK”,

name: “”

verified: false

last_cards_marked: 0

about: “”

pfp: “”

content_tags: []

last_attested: 0

identity_tags: []

badges: []

Profile_metadata: {}

},

{

address: “2aNXZ2gicvGkF7CyzBK8qguA6ycoXMcgw7usvLBRZiFK”,

name: “Mark Status”,

verified: false

last_cards_marked: 1703721486

about: “Exploring the world of Solana and building cool projects”

pfp: “https://pbs.twimg.com/profile\_images/1590877918015926272/Xl2Bd-X2\_400x400.jpg”

content_tags: [ “solana”, “nft” ]

last_attested: 1703721486

identity_tags: [“developer”, “SDE”]

Badges: [“bonk]

Profile_metadata: {}

}

2. 400 {"error": "Missing required parameters"}
  1. Update user details at signup phase 2

Description:

path api/v1/core/update-user/<address>
Type PUT
Description To update user details from the DB
Header Jwt token

Path Param:

No Param name type Description Required
1` address String Solana address of the user True

Body Param:

No Param name type Description Required
1 about String Bio for user True
2 name String Name of user True
3 pfp String Url for user image True
4 content_tags List of strings Tags which represents the content False
5 identity_tags List of strings Tags which represents the user False
6 Profile_metadata Json Metadata of user False

Example:

1. Update user details {

about: “Exploring the world of Solana and building cool projects”

pfp: “https://pbs.twimg.com/profile\_images/1590877918015926272/Xl2Bd-X2\_400x400.jpg”

content_tags: [ “solana”, “nft” ]

identity_tags: [“developer”, “SDE”]

Profile_metadata: {}

}

Response:

No Status Code Response
1. 200 {

address: “2aNXZ2gicvGkF7CyzBK8qguA6ycoXMcgw7usvLBRZiFK”,

name: “Mark Status”,

verified: false

last_cards_marked: 1703721486

about: “Exploring the world of Solana and building cool projects”

pfp: “https://pbs.twimg.com/profile\_images/1590877918015926272/Xl2Bd-X2\_400x400.jpg”

content_tags: [ “solana”, “nft” ]

last_attested: 1703721486

identity_tags: [“developer”, “SDE”]

Badges: [“bonk]

Profile_metadata: {}

}

2. 400 {"error": "Missing required parameters"}

Card APIs

  1. Get user published card details

Description

path api/v1/core/cards/published/<address>
Type GET
Description To fetch published card from the DB
Header Jwt token

Path Param

No Param name type Description Required
1` address String Solana address of the user True

Response:

No Status Code Response
1. 200 [List of json cards] [{

date: “11 Feb 2024”,

cardType: “DataCard”,

category: “Information Technology”,

content: “Visits to huggingface.co increased by”

metadata: {

contentImageUrl: “”,

contentData: “30%”

likeCount: 15,

shareCount: 20,

digCount: 15

}

}]

2. 400 {"error": "Missing required parameters"}
  1. Delete published card details for any user

Description

path api/v1/core/cards/published/<address>
Type DELETE
Description To delete published card from the DB for any user before card is not attested
Header Jwt token

Path Param

No Param name type Description Required
1` address String Solana address of the user True

Body Param

No Param name type Description Required
1` ids List of strings List of ids for published cards True

Response:

No Status Code Response
1. 200 {"message": "<count of deleted cards> published cards deleted from db for <user_address>"}
2. 400 {"error": "Missing required parameters"}
  1. Get user pending card details

Description

path api/v1/core/cards/pending/<address>
Type GET
Description To fetch pending card from the DB
Header Jwt token

Path Param

No Param name type Description Required
1` address String Solana address of the user True

Response:

No Status Code Response
1. 200 [List of json cards] [{

date: “11 Feb 2024”,

userName: “Den Brown”,

userPfp: “https://pbs.twimg.com/profile\_images/1590877918015926272/Xl2Bd-X2\_400x400.jpg”

content: “Visits to huggingface.co increased by”

links: {

domain: 'www.huggingface.co',

title: 'Hugging Face – The AI community building the future.'

}

}]

2. 400 {"error": "Missing required parameters"}
  1. Delete pending card details for any user

Description

path api/v1/core/cards/pending/<address>
Type DELETE
Description To delete removed pending card from the DB for any user
Header Jwt token

Path Param

No Param name type Description Required
1` address String Solana address of the user True

Body Param

No Param name type Description Required
1` ids List of strings List of ids for pending cards True

Response:

No Status Code Response
1. 200 {"message": "<count of deleted cards> pending cards deleted from db for <user_address>"}
2. 400 {"error": "Missing required parameters"}
  1. Get all cards and user details of any user

Description

path api/v1/core/user/<address>/published-cards/info
Type GET
Description To all published card and user from the DB
Header Jwt token

Path Param

No Param name type Description Required
1` address String Solana address of the user True

Response:

No Status Code Response
1. 200 {

"published_cards": [

{

"cardType": "DataCard",

"category": "",

"content": "Visits to huggingface.co increased by",

"date": "18 Mar 2024",

"metadata": {

"contentData": "30%",

"contentImageUrl": "",

"digCount": 15,

"likeCount": 15,

"shareCount": 20

}

},

{

"cardType": "ImageCard",

"category": "",

"content": "New ML model architecture released",

"date": "19 Mar 2024",

"metadata": {

"contentData": "",

"contentImageUrl": "https://example.com/image1.jpg",

"digCount": 20,

"likeCount": 25,

"shareCount": 30

}

},

{

"cardType": "DomainVisitCard",

"category": "",

"content": "Visits to openai.com",

"date": "20 Mar 2024",

"metadata": {

"contentData": "50,000 visits",

"contentImageUrl": "",

"digCount": 10,

"likeCount": 10,

"shareCount": 15

}

}

],

"user": {

"about": "developer with 1 YOE in java",

"address": "7B3FeQJ2SZa4Tw9gJXu7zzdmivY9ot17uXSCko1zMefh",

"badges": [

"bonk",

"bonk_v2"

],

"content_tags": [

"java",

"springBoot"

],

"identity_tags": [

"developer",

"backend"

],

"last_attested": 1710738880,

"last_cards_marked": 1710738880,

"name": "den marchov",

"pfp": "https://images.pexels.com/photos/7562313/pexels-photo-7562313.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1",

"profile_metadata": {

"alt_image_tag": "7B3FeQJ2SZa4Tw9gJXu7zzdmivY9ot17uXSCko1zMefd"

},

"verified": false

}

}

2. 400 {"error": "Missing required parameters"}
3 404 If we do not pass users in

License

This program is free software under MIT license. Please see the LICENSE file in our repository for the full text.

About

connect-backend

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages