Skip to content

API User

HumphreyLu6 edited this page Jul 9, 2020 · 1 revision

Author and Admin

0. Get current logged-in user profile: /author/current_user GET

Request format: Body not required. Authorization required.

Response status code and body format:

200
{
    "id": "https://spongebook.herokuapp.com/author/41f7b891-e535-44ef-a795-b15f1dbab035",
    "host": "https://spongebook.herokuapp.com/",
    "username": "user1",
    "displayName": "user1",
    "url": "https://spongebook.herokuapp.com/author/41f7b891-e535-44ef-a795-b15f1dbab035",
    "friends": [],
    "github": null,
    "email": "user1@email.com",
    "bio": null
}
401 Unauthorized //when token not provided.

1. As an admin or author, signup: /signup/ POST

Request format:

{
    "username":"user2",
    "email": "user2@email.com",
    "password1": "passqwer",
    "password2": "passqwer"
}

Response status code and body format:

201 Created
{
    "key": "cf0fef90f1ad4572e313df0fda01f00ca77be14f"
}

2. As an author, login: /login/ POST

Request format:

{
	"email":"user2@gmail.com",
	"password":"passqwer"
}

Response status code and body format:

200 OK
{
    "key": "cf0fef90f1ad4572e313df0fda01f00ca77be14f"
}
400 Bad Request
{
    "non_field_errors": [
        "Please wait for the approval of administrator"
    ]
}
400 Bad Request
{
    "non_field_errors": [
        "This email has not registered yet."
    ]
}
400 Bad Request
{
    "username": [
        "The email and the password are not matched."
    ]
}

3. As anyone (even anonymous), view all authors' profiles on the local server: /author GET

Request format: Body not required.

Response status code and body format:

200 OK
[
    {
        "id": "https://spongebook.herokuapp.com/author/41f7b891-e535-44ef-a795-b15f1dbab035",
        "host": "https://spongebook.herokuapp.com/",
        "username": "user1",
        "displayName": "user1",
        "url": "https://spongebook.herokuapp.com/author/41f7b891-e535-44ef-a795-b15f1dbab035",
        "friends": [],
        "github": null,
        "email": "user1@email.com",
        "bio": null
    },
    {
        "id": "https://spongebook.herokuapp.com/author/1d507e56-a6c6-42ca-be76-b6feb2cacfaa",
        "host": "https://spongebook.herokuapp.com/",
        "username": "user2",
        "displayName": "user2",
        "url": "https://spongebook.herokuapp.com/author/1d507e56-a6c6-42ca-be76-b6feb2cacfaa",
        "friends": [],
        "github": null,
        "email": "user2@email.com",
        "bio": ""
    }
]

4. As anyone (even anonymous), view an author's profile: /author/{AUTHOR_ID} GET

Example: {AUTHOR_ID} = 41f7b891-e535-44ef-a795-b15f1dbab03

http://127.0.0.1:8000/author/41f7b891-e535-44ef-a795-b15f1dbab035 GET

Request format: Body not required.

Response status code and body format:

200 OK
{
    "id": "https://spongebook.herokuapp.com/author/41f7b891-e535-44ef-a795-b15f1dbab035",
    "host": "https://spongebook.herokuapp.com/",
    "username": "user2",
    "displayName": "user1",
    "url": "https://spongebook.herokuapp.com/author/41f7b891-e535-44ef-a795-b15f1dbab035",
    "friends": [],
    "github": null,
    "email": "user1@email.com",
    "bio": null
}

5. Update an author's profile as its owner or admin: /author/{AUTHOR_ID} PATCH

Request format: Authorization required

{
    "github": "http://127.0.0.1:8000/",
    "displayName": "user1 displayname",
    "bio": "Hi, I am Jay"
}

Response status code and body format:

200 OK
{
    "id": "https://spongebook.herokuapp.com/author/21276963-75a5-466a-8a8a-295584b00bc4",
    "host": "https://spongebook.herokuapp.com/",
    "username": "user1",
    "displayName": "user1 displayname",
    "url": "https://spongebook.herokuapp.com/author/21276963-75a5-466a-8a8a-295584b00bc4",
    "friends": [],
    "github": "http://127.0.0.1:8000/",
    "email": "user1@email.com",
    "bio": "Hi, I am Jay"
}
401 Unauthorized
{
    "detail": "Authentication credentials were not provided."
}
403 Forbidden
{
    "detail": "You must be the owner of the object."
}
400 Bad Request
{
    "github": [
        "Enter a valid URL."
    ]
}

6. Delete an author's profile as its owner or admin: /author/{AUTHOR_ID}/ DELETE

Request format: Authorization required. Body not required.

Response status code and body format:

204 No Content
401 Unauthorized
{
    "detail": "Authentication credentials were not provided."
}
401 Unauthorized
{
    "detail": "Invalid token."
}
403 Forbidden
{
    "detail": "You must be the owner of the object."
}

7. Get an author's GitHub token as its owner or admin: /author/{AUTHOR_ID}/github_token GET

Request format: Authorization required. Body not required.

Response status code and body format:

200 OK
{
    "GithubToken": "token"
}
401 Unauthorized
{
    "detail": "Authentication credentials were not provided."
}
401 Unauthorized
{
    "detail": "Invalid token."
}
403 Forbidden
{
    "detail": "You must be the owner of the object."
}

8. Update an author's GitHub token as its owner or admin: /author/{AUTHOR_ID}/github_token POST

Request format: Authorization required.

{
    "GithubToken": "token"
}

Response status code and body format:

204 No Content

Clone this wiki locally