Secret Diary
The Secret Diary API allows users to register, login, create, view, and manage secret diary entries.
Resource Group ¶
Secret Diary API Root ¶
This resource returns a list of implemented endpoints. The automated grading script will only check the endpoints within this list.
This resource has the following attributes:
-
status - a boolean value indicating the success or failure of the query
-
result - a list of all implemented endpoints.
Retrieve the endpoint listGET/
Example URI
200
Headers
Content-Type: application/json
Body
{
"status": true,
"result": [
"/",
"/meta/heartbeat",
"/meta/team"
]
}
Meta ¶
Resources related to the meta-workings of the assignment.
Heartbeat ¶
This resource has the following attributes:
- status - a boolean value indication the success or failure of the query
Retrieve the server heartbeatGET/meta/heartbeat
Example URI
200
Headers
Content-Type: application/json
Body
{
"status": true
}
Team Members ¶
This resource has the following attributes:
-
status - a boolean value indication the success or failure of the query
-
result - a list of all the members full names
Retrieve the team member listGET/meta/members
Example URI
200
Headers
Content-Type: application/json
Body
{
"status": true,
"result": [
"Jeremy Heng",
"John Galt",
"Audrey Shida"
]
}
Users ¶
Resources related to users in the API.
Register a user ¶
-
username (required, string)
-
password (required, string)
-
fullname (required, string)
-
age (required, int)
This resource has the following attributes:
-
status - a boolean value indicating the success or failure of the query
-
error (Optional) - a string describing the error
If the user does not exist and all the required fields are present, then add
the user to the database and return the Response 201
with status
set to
true
.
Otherwise, return Response 200
with the status
set to false
and include
an optional error message.
The password should not be stored in plain text in the database.
Register a new userPOST/users/register
Example URI
Headers
Content-Type: application/json
Body
{
"username": "AzureDiamond",
"password": "hunter2",
"fullname": "Joey Pardella",
"age": 15
}
201
Headers
Content-Type: application/json
Body
{
"status": true
}
200
Headers
Content-Type: application/json
Body
{
"status": false,
"error": "User already exists!"
}
Authenticate a user ¶
-
username (required, string)
-
password (required, string)
This resource has the following attributes:
-
status - a boolean value indicating the success or failure of the query
-
token (Optional) - a UUID version 4 string containing the authentication token of the successfully logged in user
If the username and password combination exists in the database, then return a UUID version 4 string as the authentication token. The token should allow access to the endpoints requiring authentication.
Otherwise, return the false status
.
Authenticate an existing userPOST/users/authenticate
Example URI
Headers
Content-Type: application/json
Body
{
"username": "AzureDiamond",
"password": "hunter2"
}
200
Headers
Content-Type: application/json
Body
{
"status": true,
"result": {
"token": "6bf00d02-dffc-4849-a635-a21b08500d61"
}
}
200
Headers
Content-Type: application/json
Body
{
"status": false
}
Expire an authentication token ¶
- token (required, UUIDv4 string)
This resource has the following attributes:
- status - a boolean value indicating the success or failure of the query
If the token exists in the database and is valid, invalidate the token so that
it may not be used for authentication. Return true status
if this is
successful.
Otherwise, return the false status
.
Expire an authentication tokenPOST/users/expire
Example URI
Headers
Content-Type: application/json
Body
{
"token": "6bf00d02-dffc-4849-a635-a21b08500d61",
}
200
Headers
Content-Type: application/json
Body
{
"status": true
}
200
Headers
Content-Type: application/json
Body
{
"status": false
}
Retrieve user information ¶
- token (required, UUIDv4 string)
This resource has the following attributes:
-
status - a boolean value indicating the success or failure of the query
-
username (Optional) - a string containing the user’s username
-
fullname (Optional) - a string containing the user’s full name
-
age (Optional) - a string containing the user’s age
-
error (Optional) - a string indicating the reason for the error
If the token is valid, return the username
, fullname
, and age
of the user
represented by the token.
Otherwise, return the false status
.
Retrieve authenticated user informationPOST/users
Example URI
Headers
Content-Type: application/json
Body
{
"token": "6bf00d02-dffc-4849-a635-a21b08500d61",
}
200
Headers
Content-Type: application/json
Body
{
"status": true,
"result": {
"username": "audrey123talks",
"fullname": "Audrey Shida",
"age": 14
}
}
200
Headers
Content-Type: application/json
Body
{
"status": false,
"error": "Invalid authentication token."
}
Diary ¶
Resources related to diary entries
Retrieve list of diary entries ¶
This resource has the following attributes:
-
status - a boolean value indicating the success or failure of the query
-
result (Optional) - a list of entry objects representing the requested diary entries
-
error (Optional) - a string describing the error
The diary entry object has the following structure:
-
id - an int representing the unique entry
-
title - a string representing the entry title
-
author - a string representing the author’s name
-
publish_date - a string in ISO 8601 format representing the date the entry was published
-
public - a boolean indicating if the entry is private or public
-
text - a string containing the body of the entry
The GET request endpoint will return all public diary entries without any parameters.
When querying for the authenticated user’s diary entries with a POST request, the following parameters are used:
- token (required, UUIDv4 string)
Retrieve all public diary entriesGET/diary
Example URI
200
Headers
Content-Type: application/json
Body
{
"status": true,
"result": [
{
"id": 1,
"title": "My First Project",
"author": "ashrugged",
"publish_date": "2013-02-27T13:37:00+00:00",
"public": true,
"text": "If you don't know, the thing to do is not to get scared, but to learn."
},
{
"id": 2,
"title": "A New Lesson!",
"author": "audrey123talks",
"publish_date": "2013-02-29T13:37:00+00:00",
"public": true,
"text": "Check out my latest video!"
}
]
}
Retrieve all entries belonging to an authenticated userPOST/diary
Example URI
Headers
Content-Type: application/json
Body
{
"token": "6bf00d02-dffc-4849-a635-a21b08500d61",
}
200
Headers
Content-Type: application/json
Body
{
"status": true,
"result": [
{
"id": 2,
"title": "A New Lesson!",
"author": "audrey123talks",
"publish_date": "2013-02-29T13:37:00+00:00",
"public": true,
"text": "Check out my latest video!"
},
{
"id": 3,
"title": "No One Can See This Post",
"author": "audrey123talks",
"publish_date": "2013-02-29T13:38:00+00:00",
"public": false,
"text": "It is very secret!"
}
]
}
200
Headers
Content-Type: application/json
Body
{
"status": false,
"error": "Invalid authentication token."
}
Create a new diary entry ¶
-
token (required, UUIDv4 string)
-
title (required, string)
-
public (required, boolean)
-
text (required, string)
This resource has the following attributes:
-
status - a boolean value indicating the success or failure of the query
-
result (Optional) - an int containing the id of the newly created entry
-
error (Optional) - a string describing the error
The entry should be made committed to a database if the creation is successful.
Create a new diary entryPOST/diary/create
Example URI
Headers
Content-Type: application/json
Body
{
"token": "6bf00d02-dffc-4849-a635-a21b08500d61",
"title": "No One Can See This Post",
"public": false,
"text": "It is very secret!"
}
201
Headers
Content-Type: application/json
Body
{
"status": true,
"result": {
"id": 2
}
}
200
Headers
Content-Type: application/json
Body
{
"status": false,
"error": "Invalid authentication token."
}
Delete an existing diary entry ¶
-
token (required, UUIDv4 string)
-
id (required, int)
This resource has the following attributes:
-
status - a boolean value indicating the success or failure of the query
-
error (Optional) - a string describing the error
The entry should be purged from the database if the deletion is successful.
Delete an existing diary entryPOST/diary/delete
Example URI
Headers
Content-Type: application/json
Body
{
"token": "6bf00d02-dffc-4849-a635-a21b08500d61",
"id": 2
}
200
Headers
Content-Type: application/json
Body
{
"status": true,
}
200
Headers
Content-Type: application/json
Body
{
"status": false,
"error": "Invalid authentication token."
}
Adjust diary entry permissions ¶
-
token (required, UUIDv4 string)
-
id (required, int)
-
public (required, boolean)
This resource has the following attributes:
-
status - a boolean value indicating the success or failure of the query
-
error (Optional) - a string describing the error
The entry should either be made public or private depending on the value of
public
if the adjustment is successful.
Adjust diary entry permissionsPOST/diary/permission
Example URI
Headers
Content-Type: application/json
Body
{
"token": "6bf00d02-dffc-4849-a635-a21b08500d61",
"id": 1,
"public": true
}
200
Headers
Content-Type: application/json
Body
{
"status": true,
}
200
Headers
Content-Type: application/json
Body
{
"status": false,
"error": "Invalid authentication token."
}