Skip to content

leman-kg/users-rest-api-flask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Requirements

Installation

App

  1. Manually generate a string of random characters and insert it into .env file after SECRET_KEY=: SECRET_KEY='<your_strting_here>'

  2. Open your OS terminal, change the working directory to the project and run the command below: (if you already have another app running on port 8000, please find the line - 8000:8080 and replace 8000 with a free port): docker-compose -p cbtask up -d --build This will install and run the app

Postman (optional)

For your convenience I created the endpoints collection that you can import into your Postman. Just open Postman and import Users-API.postman_collection.json file that comes with the project

How to use

NOTE 1: if you changed the port please use it in the steps below instead of 8000.

NOTE 2: All endpoint specs are described in API Doc below

  1. Create a user: the DB is empty, so you'll need to create the first user by using create user endpoint
  2. Send username and password that you created login endpoint to authenticate
  3. In response you will receive an auth token (session duration: 30 min). You should use it to get authorized in all other endpoints: 3.1 (Postman) In the "Authorization" tab of a request choose Type: Bearer Token and insert your token into the "Token" field 3.2 If you use curl or any other client you'll need to pass header: Authorization: Bearer <token>

API Doc

  1. create user
  2. login
  3. view all users
  4. view user by id
  5. update user by id
  6. delete user by id
  7. purge user by id

Endpoints


1. create user

Endpoint:

Method: POST
Type: FORMDATA
URL: http://localhost:8000/users/create

Body:

Key Value
username john_doe
password qwerty123
email [email protected]
info Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

2. login

Endpoint:

Method: POST
Type: FORMDATA
URL: http://localhost:8000/login

Body:

Key Value
username john_doe
password qwerty123

3. view all users

Endpoint:

Method: GET
Type:
URL: http://localhost:8000/users

Query params:

Key Value Description
page 1 Default: 1
per_page 10 Default: 10

4. view user by id

Endpoint:

Method: GET
Type:
URL: http://localhost:8000/users/:id

URL variables:

Key Value
id 1

5. update user by id

Endpoint:

Method: POST
Type: FORMDATA
URL: http://localhost:8000/users/update/:id

URL variables:

Key Value
id 1

Body:

Key Value
info Changed info

6. delete user by id

Endpoint:

Method: DELETE
Type:
URL: http://localhost:8000/users/delete/:id

URL variables:

Key Value
id 1

7. purge user by id

Endpoint:

Method: DELETE
Type:
URL: http://localhost:8000/users/purge/:id

URL variables:

Key Value
id 1

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published