GithubHelp home page GithubHelp logo

sample_drf's Introduction

Sample API's using DRF

Status code

  • 200 OK – Everything is working
  • 201 OK – New resource has been created
  • 204 OK – The resource was successfully deleted
  • 304 Not Modified – The client can use cached data
  • 400 Bad Request – The request was invalid or cannot be served. The exact error should be explained in the error payload. E.g. „The JSON is not valid“
  • 401 Unauthorized – The request requires an user authentication
  • 403 Forbidden – The server understood the request, but is refusing it or the access is not allowed.
  • 404 Not found – There is no resource behind the URI.
  • 422 Un-processable Entity – Should be used if the server cannot process the entity, e.g. if an image cannot be formatted or mandatory fields are missing in the payload.
  • 500 Internal Server Error – API developers should avoid this error. If an error occurs in the global catch blog, the stack-trace should be logged and not returned as response.

Setup project for development:

  • Clone the project
  • Install packages mentioned in the runtime.txt
  • Create virtualenv "python3.6 -m venv <virtual_path>"
  • Activate and install requirements.txt
  • Create a .env file in the root folder, using env.example as template

Docs link: "http://domain.com>/docs/", it will be enabled only if REST_FRAMEWORK_DOC_ENABLED=True

  • Listing example output:
{
    "count": 10,
    "next": "http://127.0.0.1:8000/api/v1/posts/?limit=2&offset=2",
    "previous": null,
    "results": [
        {
            "text": "test",
            "user": {
                "id": 1,
                "username": "ranju",
                "name": "Ranju R"
            },
            "created": "2018-07-31T11:32:14.727142Z"
        },
        {
            "text": "test",
            "user": {
                "id": 1,
                "username": "ranju",
                "name": "Ranju R"
            },
            "created": "2018-07-31T11:31:43.644533Z"
        }
    ]
}

Status code: 200
  • Error listing for each field
{
    "text": [
        "This field is required."
    ]
}

Status code: 400
  • Created
{
    "text": "Test",
    "user": {
        "id": 1,
        "username": "ranju",
        "name": "Ranju R"
    },
    "created": "2018-07-31T13:01:52.091217Z"
}

Status code: 201
  • Detail
{
    "text": "Test",
    "user": {
        "id": 1,
        "username": "ranju",
        "name": "Ranju R"
    },
    "created": "2018-07-31T13:01:52.091217Z"
}

Status code: 200

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.