Giter VIP home page Giter VIP logo

django_api's Introduction

Django API Project

A django template

Instaltion

Install the project via python virtualenv

Create and launch a virtualenv

python3 -m venv .env
source .env/bin/active

Install the project requirements (within the virtualenv) and migrate to create the database.

pip install -r requirements.txt
python manage.py migrate

Install the project via docker-compose

Start docker-compose

docker-compose up

Migrations are running on starting doker-compose no need to re run

Endpoints

GET /api/scrapers/

HTTP Status Code 200

curl --request GET http://localhost:8000/api/scrapers/

Response example HTTP Status Code 200

{
  "scrapers": [
    {
      "id": 2,
      "created_at": "2020-06-30T22:16:41.375386+00:00",
      "currency": "bitcoin",
      "frequency": 60,
      "value": 9150.05,
      "value_updated_at": "2020-06-30T22:21:58.108506+00:00"
    },
    {
      "id": 3,
      "created_at": "2020-06-30T22:21:08.028843+00:00",
      "currency": "tether",
      "frequency": 100,
      "value": 0.999931,
      "value_updated_at": "2020-06-30T22:22:10.522852+00:00"
    }
  ]
}

POST /api/scrapers/

HTTP Status Code 200

curl --header "Content-Type: application/json" \
     --request POST \
     --data '{"currency": "Dogecoin", "frequency": 25}' \
     http://localhost:8000/api/scrapers/

Response example

{
  "id": 5,
  "created_at": "2020-07-01T22:07:47.797137+00:00",
  "currency": "Dogecoin",
  "frequency": 25
}

In case of any validation error

HTTP Status Code 400

Response example

{
    "error": {
        "currency": [
            {
                "message": "This field is required.",
                "code": "required"
            }
        ],
        "frequency": [
            {
                "message": "This field is required.",
                "code": "required"
            }
        ]
    }
}

PUT /api/scrapers/

HTTP Status Code 200

curl --header "Content-Type: application/json" \
     --request PUT \
     --data '{"id": 4, "frequency": 35}' \
     http://localhost:8000/api/scrapers/

Response example

{
    "msg": "Scraper updated"
}

In case of any validation error

HTTP Status Code 400

Response example

{
    "error": {
        "frequency": [
            {
                "message": "This field is required.",
                "code": "required"
            }
        ],
        "id": [
            {
                "message": "This field is required.",
                "code": "required"
            }
        ],
        "value": [
            {
                "message": "Enter a whole number.",
                "code": "invalid"
            }
        ]
    }
}

DELETE /api/scrapers

HTTP Status Code 200

curl --header "Content-Type: application/json" \
     --request DELETE \
     --data '{"id": 4}' \
     http://localhost:8000/api/scrapers/

Response example

{
    "msg": "Scraper deleted"
}

In case of any validation error

HTTP Status Code 400

Response example

{
    "error": {
        "id": [
            {
                "message": "The scraper was not found.",
                "code": "not_found"
            }
        ]
    }
}

Tests

To run the tests for the project run the follow script

python manage.py test api

And test are automated thanks to github actions ♥️

Here are automated test runned in this project

django_api's People

Contributors

eriksape avatar

Watchers

 avatar  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.