Code Monkey home page Code Monkey logo

web-api's Introduction

Build Status codecov

web-api

A sample of api with external api dependency

Install dependencies.

We use poetry to manage dependencies, so make sure you have it installed.

make install

Create .env

cp default.env .env

After create database test and set on .env file Update the values of databases, PRODUCTS_API and SECRET_KEY

Sync migrations

make migrate

Create a user

make createuser

Run

make run

How to use

to simplify, the examples bellow use httpie

Authentication

request

 http -f POST http://localhost:8000/auth/login username=outrouser password=senha

response

HTTP/1.1 200 OK
content-length: 178
content-type: application/json
date: Sun, 3 Oct 1991 02:13:05 GMT
server: uvicorn

{
    "access_token": "<TOKEN>",
    "token_type": "bearer"
}

Create client

request

 http POST http://localhost:8000/clients/ "Authorization: Bearer <TOKEN>" username=Guilherme [email protected] favorite_products:='[{"id": "1bf0f365-fbdd-4e21-9786-da459d78dd1f"}]

response

HTTP/1.1 201 Created
content-length: 363
content-type: application/json
date: Sun, 3 Oct 1991 02:13:05 GMT
server: uvicorn

{
    "email": "[email protected]",
    "favorite_products": [
        {
            "id": "1bf0f365-fbdd-4e21-9786-da459d78dd1f",
            ... and other fields from your api
        }
    ],
    "id": "8a7fb195-81f6-433f-a084-2348977e6950",
    "username": "Guilherme"
}

Update client

request

 http PUT http://localhost:8000/clients/7a7fb195-71f6-433f-a084-2348977e6950 "Authorization: Bearer <TOKEN>" username=Guilherme [email protected] favorite_products:='[{"id": "1bf0f365-fbdd-4e21-9786-da459d78dd1f"}]'

response

HTTP/1.1 200 OK
content-length: 368
content-type: application/json
date: Sun, 3 Oct 1991 02:13:05 GMT
server: uvicorn

{
    "email": "[email protected]",
    "favorite_products": [
        {
            "id": "1bf0f365-fbdd-4e21-9786-da459d78dd1f",
            ... and other fields from your api
        }
    ],
    "id": "7a7fb195-71f6-433f-a084-2348977e6950",
    "username": "Guilherme"
}

List clients

request

 http GET http://localhost:8000/clients/ "Authorization: Bearer <TOKEN>"

response

HTTP/1.1 200 OK
content-length: 2887
content-type: application/json
date: Sun, 3 Oct 1991 02:22:38 GMT
server: uvicorn

[
    {
        "email": "[email protected]",
        "favorite_products": [
            {...}
        ],
        "id": "2aea592a-45d8-4481-a887-403258bfcb32",
        "username": "client-username"
    },
    {...}
]

Delete client

request

 http DELETE http://localhost:8000/clients/<CLIENT-ID> "Authorization: Bearer <TOKEN>"

response

HTTP/1.1 204 No Content
content-length: 4
content-type: application/json
date: Sun, 3 Oct 1991 02:28:18 GMT
server: uvicorn

Docs

Fast api generate automatic documentation http://localhost:8000/docs alt text

web-api's People

Contributors

guibeira avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.