Skip to content

Latest commit

 

History

History
226 lines (162 loc) · 2.54 KB

api_doc.md

File metadata and controls

226 lines (162 loc) · 2.54 KB

Carbon Footprint API Documentation

Endpoints :

List of available endpoints :

  • POST /register
  • POST /login
  • POST /carbon/tobacco
  • POST /carbon/vehicle
  • GET /products
  • POST /product/payment/:id

1. POST /register

Description :

  • Create a new user

Request :

  • body :
{
  "username": "string",
  "email": "string",
}

Response(201 - Created)

{
  "id": "integer",
  "email": "string",
}

Resoponse(400 - Bad Request)

{
    "messsage" : "Email address already in use!" 
}
OR
{
    "messsage" : "Email is required"
}
OR
{
     "messsage" : "Email Format is required"
}
OR
{
     "messsage" : "Password is required"
}

2. POST /login

Description :

  • Log in into website

Request :

  • body :
{
  "email": "string",
  "password": "string",
}

Response(200 - OK)

{
  "access_token" 
}

Resoponse(404 - Bad Request)

{
    "message" : "Bad Request"
}

Response(401 - Unauthorized)

{
    "message": "Invalid email or password" 
}

3. POST /carbon/tobbaco

-Description: get result of carbon footprint from cigarretes price and time to plant a tree in month

Request :

  • body :
{
  "price": "integer",
}

Response(200 - OK)

{
  "co2e":"integer",
  "time" : "integer" 
}

Resoponse(404 - Bad Request)

{
    "message" : "Bad Request"
}

4. POST /carbon/vehicle

-Description: get result of carbon footprint from distance in km and time to plant a tree in month

Request :

  • body :
{
  "distance": "integer",
}

Response(200 - OK)

{
  "co2e":"integer",
  "time" : "integer" 
}

Resoponse(404 - Bad Request)

{
    "message" : "Bad Request"
}

5. GET /products

Description :

  • get all product
[
    {
         "id": 1,
        "name": "Mahoni Tree",
        "imgUrl": "https://i.pinimg.com/564x/25/24/3f/25243fea81803e0f376cdb9a20625520.jpg",
        "description": "We are super excited to announce that starting in 1st of May 2023, we are planting trees when you shop from us!",
        "price": 125000,
    }
    ...,
]

6 POST /product/payment/:id

Description : Create payment for buying products by id

Response(201 - OK)

{
  "token" : "string",
  "redicrect_url" : "string" 
}

Resoponse(404 - Bad Request)

{
    "message" : "Bad Request"
}

Global Error

Response(401 - Unauthorized)

{
    "message": "Invalid Token" 
}
``

_Response (500 - Internal Server Error)_

```json
{
  "message": "Internal server error"
}