5 REST API
Patryk Dolata edited this page 2020-12-17 17:10:46 +01:00

Welcome on the SmartPicasso REST API wiki!

Here you can find available endpoints in our REST app.

Authentication

Authentication is performing with JWT token. You must add Bearer <token> to the Authorization header if endpoint requires auth.

POST /api/authenticate

Endpoint using to authenticate user during signing in

  • requires authentication:

    False

  • uri:

    /api/authenticate

  • request body:

      {
          "email": "example@test.com",
          "password": "pass"
      }
    
  • success response example:

    status_code: 200

      {
          "success": "True",
          "status_code": 200,
          "message": "User logged in successfully",
          "token": "token"
      }
    
  • error response example:

    status_code: 400

      {
          "non_field_errors": [
              "An user with provided email and password is not found"
          ]
      }
    

POST /api/register

Endpoint using to register new user

  • requires authentication:

    False

  • uri:

    /api/register

  • request body:

      {
          "email": "example@test.com",
          "password": "pass",
          "profile": {
              "username": "j.doe",
              "first_name": "John",
              "last_name": "Doe"
          }
      }
    
  • success response example:

    status_code: 201

      {
          "success": "True",
          "status_code": 201,
          "message": "User registered successfully"
      }
    
  • error response examples:

    status_code: 400

      {
          "email": [
              "user with this email address already exists."
          ]
      }
    
    
      or
    
    
      {
          "profile": {
              "username": [
                  "user profile with this username already exists."
              ]
          }
      }
    
      or
    
      {
          "email": [
              "user with this email address already exists."
          ],
          "profile": {
              "username": [
                  "user profile with this username already exists."
              ]
          }
      }
    

GET /api/profile

Endpoint using to retrieve logged user profile

  • requires authentication:

    True

  • uri:

    /api/profile

  • success response example:

    status_code: 200

      {
          "success": "True",
          "status_code": 200,
          "message": "User profile fetched successfully",
          "profile": {
              "username": "j.doe",
              "first_name": "John",
              "last_name": "Doe"
          }
      }
    
  • error response examples:

    status_code: 401

      {
          "detail": "Authentication credentials were not provided."
      }
    

    or

    status_code: 404

       {
          "success": "False",
          "status_code": 404,
          "message": "User profile does not exist",
          "error": "UserProfile matching query does not exist." 
       }
    

POST /api/projects

Endpoint using to create new user's project

  • requires authentication:

    True

  • uri:

    /api/projects

  • request body:

      {
          "name": "project_1"
      }
    
  • success response example:

    status_code: 201

      {
          "id": "some_id",
          "name": "project_1",
          "created_at": "2020-12-17T16:07:42.050666Z",
          "updated_at": "2020-12-17T16:07:42.050707Z"
      }
    
  • error response examples:

    status_code: 401

      {
          "detail": "Authentication credentials were not provided."
      }
    

GET /api/projects

Endpoint using to retrieve all user's projects

  • requires authentication:

    True

  • uri:

    /api/projects

  • success response example:

    status_code: 200

      [
          {
              "id": "id_1",
              "name": "project_1",
              "created_at": "2020-12-15T15:32:33.901299Z",
              "updated_at": "2020-12-15T15:32:33.901370Z"
          },
          {
              "id": "id_2",
              "name": "project_2",
              "created_at": "2020-12-17T16:07:42.050666Z",
              "updated_at": "2020-12-17T16:07:42.050707Z"
          }
      ]
    
  • error response examples:

    status_code: 401

      {
          "detail": "Authentication credentials were not provided."
      }