Skip to content

Author API Documentation

keanweng97 edited this page Apr 15, 2021 · 24 revisions

API used to manage all aspects of user/author identity on Konnection. It offers endpoints so users can sign up, log in, update and retrieve their profiles.

Create a superuser

Go to the same directory as manage.py, enter the following line into and follow the system instruction

python manage.py createsuperuser

1.Get an Author Profile

Endpoints

Get: /api/author/{id}/

Getting an author's profile

Endpoint Requirements

  1. Provide Token in the header for authentication purpose
  2. Logged in user must be approved by admin

Request Header

Request Header Required / optional Description Type
Authorization required Authentication Token String

Sample header --header "Authorization: Token 7ccf51cf9b2b518d789bdeaf5de1db0e530e1ab5"

Sample Response

The following is a sample response from the endpoint:

{
    "username": "test",
    "type": "author",
    "id": "6oidshfihfdiubw-12124",
    "host": "https://konnection-client.herokuapp.com",
    "displayName": "test",
    "url": "https://konnection-client.herokuapp.com/author/6oidshfihfdiubw-12124",
    "github": "https://blob.github.com"
}

Response Status Code

  • 200 OK Returns author object
  • 401 Unauthorized User not logged in
  • 400 Bad Request Not a valid user ID

2.Get Logged In Author Profile

Endpoints

GET: /api/author/me/

Getting the profile of the logged in author.

Endpoint Requirements

  1. Provide Token in the header for authentication purposes.
  2. Logged in user must be approved by admin

Request Header

Request Header Required / optional Description Type
Authorization required Authentication Token String

Sample header --header "Authorization: Token 7ccf51cf9b2b518d789bdeaf5de1db0e530e1ab5"

Sample Response

The following is a sample response from the endpoint:

{
    "username": "test",
    "type": "author",
    "id": "6oidshfihfdiubw-12124",
    "host": "https://konnection-client.herokuapp.com",
    "displayName": "test",
    "url": "https://konnection-client.herokuapp.com/author/6oidshfihfdiubw-12124",
    "github": "https://blob.github.com"
}

Response Status Code

  • 200 OK Returns author object
  • 401 Unauthorized User not logged in

3.Create an author

Endpoints

POST: /api/author/create/

Create an author account.

Endpoint Requirements

  1. Logged in user must be approved by admin

Request Body

Request body Required / optional Description Type
username required The user's desired username String
password required The user's desired password String

Sample Response

The following is a sample response from the endpoint:

{}

Response Status Code

  • 201 Created User is successfully created

4.Authenticate an Author

Endpoints

POST: /api/author/auth/

To authenticate/login an author. The endpoint will return a token belongs to that author after the authentication.

Endpoint Requirements

  1. Provide Token in the header for authentication purposes.
  2. Logged in user must be approved by admin

Request Header

Request Header Required / optional Description Type
Authorization required Authentication Token String

Sample header --header "Authorization: Token 7ccf51cf9b2b518d789bdeaf5de1db0e530e1ab5"

Sample Response

The following is a sample response from the endpoint:

{
    "token":"dsfjosjfjsdlfnksanfk-noawenfon",
}

Response Status Code

  • 200 OK Returns a token object

5.Update an Author Profile

Endpoints

PUT: /api/author/{id}/

Author to update their profile

Endpoint Requirements

  1. Provide Token in the header for authentication purposes.
  2. Logged in user must be approved by admin

Request Header

Request Header Required / optional Description Type
Authorization required Authentication Token String

Sample header --header "Authorization: Token 7ccf51cf9b2b518d789bdeaf5de1db0e530e1ab5"

Request Body

Request Body Required / optional Description Type
displayName optional The user's desired display name String
github optional The user's desired GitHub URL String

Sample Response

The following is a sample response from the endpoint:

{
        "username": "testing12",
        "type": "author",
        "id": "xxxxxxxxxxx",
        "host": "",
        "displayName": "",
        "url": "",
        "github": ""
}

Response Status Code

  • 200 OK Returns author object
  • 401 Unauthorized Does not have permission to edit this profile

6.Get all local authors

Endpoints

GET: /api/authors/

To get a list of all local authors, excluding superuser and not admin approved author.

Endpoint Requirements

  1. Provide Token in the header for authentication purposes.
  2. Logged in user must be approved by admin

Request Header

Request Header Required / optional Description Type
Authorization required Authentication Token String

Sample header --header "Authorization: Token 7ccf51cf9b2b518d789bdeaf5de1db0e530e1ab5"

Sample Response

The following is a sample response from the endpoint:

[
    {
        "username": "abc001",
        "type": "author",
        "id": "xxx",
        "host": "xxx",
        "displayName": "",
        "url": "",
        "github": ""
    },
    ...
]

Response Status Code

  • 200 OK Returns a list of local authors

7.Get all authors (local and remote)

Endpoints

GET: /api/all-authors/

To get a list of all local and remote authors, excluding superuser and not admin approved author.

Endpoint Requirements

  1. Provide Token in the header for authentication purposes.
  2. Logged in user must be approved by admin

Request Header

Request Header Required / optional Description Type
Authorization required Authentication Token String

Sample header --header "Authorization: Token 7ccf51cf9b2b518d789bdeaf5de1db0e530e1ab5"

Sample Response

The following is a sample response from the endpoint:

{
    "errors": {
        "https://wrong-credentials.com/api/authors/": {
            "detail": "Invalid username/password."
        }
    },
    "authors": [
        {
            "username": "abc001",
            "type": "author",
            "id": "xxx",
            "host": "xxx",
            "displayName": "",
            "URL": "",
            "github": ""
        },
        {
            "type": "author",
            "id": "https://team6-project-socialdistrib.herokuapp.com/author/84f4ec29d64d488794550052024024b1",
            "host": "https://team6-project-socialdistrib.herokuapp.com/",
            "displayName": "remote",
            "url": "https://team6-project-socialdistrib.herokuapp.com/author/84f4ec29d64d488794550052024024b1",
            "github": "www.github.com/remote"
        }
    ]
}

Response Status Code

  • 200 OK Returns a list of local and remote authors