Giter Club home page Giter Club logo

django-rest-api-jwt's Introduction

Django Rest API With JWT

Create User

Request

curl -X POST \
  http://localhost:8000/api/v1/auth/register/ \
  -H 'content-type: application/json' \
  -d '{
    	"username": "new_user",
    	"password": "new_pass",
    	"email": "[email protected]"
      }'

Login

Request

curl -X POST \
  http://localhost:8000/api/v1/auth/login/ \
  -H 'content-type: application/json' \
  -d '{
    	"username": "new_user",
    	"password": "new_pass"
      }'

Response

{
    token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6Im5ld191c2VyIiwiZXhwIjoxNTQwNDkyMTQ2LCJlbWFpbCI6Im5ld191c2VyQG1haWwuY29tIn0.8_8S-5MYY-gXkkJ-emT97s-aW8JhMEGnOyahS20uPtQ"
}

Create Token

Request

curl -X POST \
  http://localhost:8000/api-token-auth/ \
  -H 'content-type: application/json' \
  -d '{
        "username": "new_user",
        "password": "new_pass"
      }'

Response

{
    token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6Im5ld191c2VyIiwiZXhwIjoxNTQwNDkyMTQ2LCJlbWFpbCI6Im5ld191c2VyQG1haWwuY29tIn0.8_8S-5MYY-gXkkJ-emT97s-aW8JhMEGnOyahS20uPtQ"
}

Songs

Request

curl -X GET \
  http://localhost:8000/api/v1/songs/ \
  -H 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6Im5ld191c2VyIiwiZXhwIjoxNTQwNDkyMTQ2LCJlbWFpbCI6Im5ld191c2VyQG1haWwuY29tIn0.8_8S-5MYY-gXkkJ-emT97s-aW8JhMEGnOyahS20uPtQ' \

Response

[
    {
        "title": "Kiss from a rose",
        "artist": "Seal"
    },
    {
        "title": "Gotham city",
        "artist": "R Kelly"
    },
    {
        "title": "World greatest",
        "artist": "R Kelly"
    },
    {
        "title": "Always",
        "artist": "James Ingram"
    }
]

Find Song

Request

curl -X GET \
  http://localhost:8000/api/v1/songs/1/ \
  -H 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6Im5ld191c2VyIiwiZXhwIjoxNTQwNTU3Mjc3LCJlbWFpbCI6Im5ld191c2VyQG1haWwuY29tIn0.zCPIfm25UD3ySF7ivxfKwBEIaz4x68U8CY0pRCkJWTg' \

Response

{
    "title": "Kiss from a rose",
    "artist": "Seal"
}

Create Song

Request

curl -X POST \
  http://localhost:8000/api/v1/songs/ \
  -H 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6Im5ld191c2VyIiwiZXhwIjoxNTQwNTU3Mjc3LCJlbWFpbCI6Im5ld191c2VyQG1haWwuY29tIn0.zCPIfm25UD3ySF7ivxfKwBEIaz4x68U8CY0pRCkJWTg' \
  -H 'content-type: application/json' \
  -d '{
        "title": "Lifelines",
        "artist": ""
      }'

Response

{
    "title": "Lifelines",
    "artist": ""
}

Update Song

Request

curl -X PUT \
  http://localhost:8000/api/v1/songs/5/ \
  -H 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6Im5ld191c2VyIiwiZXhwIjoxNTQwNTU3Mjc3LCJlbWFpbCI6Im5ld191c2VyQG1haWwuY29tIn0.zCPIfm25UD3ySF7ivxfKwBEIaz4x68U8CY0pRCkJWTg' \
  -H 'content-type: application/json' \
  -d '{
        "title": "Lifelines",
        "artist": "A-ha"
      }'

Response

{
    "title": "Lifelines",
    "artist": "A-ha"
}

Remove Song

Request

curl -X DELETE \
  http://localhost:8000/api/v1/songs/5/ \
  -H 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6Im5ld191c2VyIiwiZXhwIjoxNTQwNTU3Mjc3LCJlbWFpbCI6Im5ld191c2VyQG1haWwuY29tIn0.zCPIfm25UD3ySF7ivxfKwBEIaz4x68U8CY0pRCkJWTg' \

django-rest-api-jwt's People

Contributors

danieldpn avatar

Stargazers

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