This documentation demonstrates how you can write an API reference guide using Squarespace. For a full description of how I created this template, see this blog post. For example content, I used this REST API Boilerplate created by Daniel Sousa.
Please note that the Initech name and URL are fake and are just used for example purposes.
The Initech API is a simple and powerful REST API. Our API has predictable, resource-oriented URLs, and uses HTTP response codes to indicate API errors. We use built-in HTTP features, like HTTP authentication and HTTP verbs, which are understood by off-the-shelf HTTP clients. JSON is returned by all API responses, including errors.
https://api.initech.com/v1/
Get the API system status
curl https://api.initech.com/v1/status \
-X GET
OK
This section describes frequently used fields and/or data structures so that they don't have to be described as part of every endpoint.
Field | Description |
---|---|
commonFieldA
string |
commonFieldA description |
commonFieldB
string |
commonFieldB description |
Initech uses conventional HTTP response codes to indicate the success or failure of an API request. In general: Codes in the 2xx range indicate success. Codes in the 4xx range indicate an error that failed given the data provided (e.g., a required parameter was omitted, invalid value, etc.). Codes in the 5xx range indicate an error with Initech's system processing.
Important: Different error types can be added and removed over time so you should make sure your application accepts new ones as well.
Field | Description |
---|---|
code
integer
|
HTTP status code |
message
string
|
Error message. Typcially, the corresponding HTTP message (e.g. "OK", "Internal Server Error", etc.) |
errors
array of strings or objects
|
Descriptive error messages |
In this section, you would typically describe common error types (e.g. rate_limit_exceeded); however, the REST API Boilerplate doesn't make use of such identifiers. Instead, the Boilerplate uses the message field as a quasi error type as follows:
Error Id | Description |
---|---|
Unauthorized
|
Incorrect email, password or token. Should probably be renamed to "Authentication Error", as "Unauthorized" is synonymous with the "Forbidden" erorr (see below). Other flavors of this type include "Incorrect email or password" and "Incorrect email or refreshToken". |
Forbidden
|
Authorization/permission error (e.g. "Only admins can create the data") |
Validation Error/Erro de Validação
|
Validation error (e.g. a required field was missing) |
User does not exist
|
User does not exist for the specified Id |
An email is required to generate a token
|
An email is required to generate a token |
{
"code": 500,
"message": "Internal Server Error",
"errors": ["Failed to process TPS report"]
}
Field | Description |
---|---|
tokenType
string
|
Access Token's type
Allowed values: Bearer
|
accessToken
string
|
Authorization Token |
refreshToken
string
|
Token to get a new accessToken after expiration time |
expiresIn
timestamp
|
The time at which the currect accessToken will expire |
Create/register a new user
Field | Description |
---|---|
email
string
|
User's email address |
password
string
|
User's password |
Field | Description |
---|---|
token
object
|
See Token Object |
user
object
|
See User Object |
curl https://api.initech.com/v1/auth/register \
-X POST \
-H 'Content-Type: application/json' \
-d '{
"email": "milton.waddams@initech.com",
"password": "ILuvStapl3rs"
}'
{
"token": {
"tokenType": "Bearer",
"accessToken": "eyJ0eXAiOiJKV1Qi...",
"refreshToken": "5b7b5ceb7873fabfe...",
"expiresIn": "2018-08-21T00:44:31.548Z"
},
"user": {
"id": "5b7b5ceb7873fabfe7829c25",
"email": "milton.waddams@initech.com",
"role": "user",
"createdAt": "2018-08-21T00:29:31.441Z"
}
}
Log in and get an access token
Field | Description |
---|---|
email
string
|
User's email address |
password
string
|
User's password |
Same as that of the registration response |
curl https://api.initech.com/v1/auth/login \
-X POST \
-H 'Content-Type: application/json' \
-d '{
"email": "milton.waddams@initech.com",
"password": "ILuvStapl3rs"
}'
{
"token": {
"tokenType": "Bearer",
"accessToken": "eyJ0eXAiOiJK...",
"refreshToken": "5b7b5ceb7873f...",
"expiresIn": "2018-08-21T01:42:14.534Z"
},
"user": {
"id": "5b7b5ceb7873fabfe7829c25",
"email": "milton.waddams@initech.com",
"role": "user",
"createdAt": "2018-08-21T00:29:31.441Z"
}
}
Refresh expired accessToken
Field | Description |
---|---|
email
string
|
User's email address |
refreshToken
string
|
Refresh token aquired when user logged in |
Field | Description |
---|---|
token
object
|
See registration response |
curl https://api.initech.com/v1/auth/login \
-X POST \
-H 'Content-Type: application/json' \
-d '{
"email": "milton.waddams@initech.com",
"refreshToken": "5b7b5ceb7873fabfe7829c25..."
}'
{
"tokenType": "Bearer",
"accessToken": "eyJ0eXAiOiJKV1Q...",
"refreshToken": "5b7b5ceb7873fab...",
"expiresIn": "2018-08-21T01:53:54.551Z"
}
Field | Description |
---|---|
id
string
|
User's id |
name
string,optional
|
User's name |
email
string
|
User's email |
role
string
|
User's role
Allowed values: user, admin
|
createdAt
timestamp
|
The time at which the user was created |
Get a list of users
Field | Description |
---|---|
user
object[]
|
Array of User Objects |
curl https://api.initech.com/v1/users \
-X GET \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer xxx.xxx.xxx'
[
{
"id": "5b7c20b3aa7a77c62e6b3955",
"email": "milton@initech.com",
"role": "admin",
"createdAt": "2018-08-21T14:24:51.761Z"
},
{
"id": "5b7b5ceb7873fabfe7829c25",
"email": "lumbergh@initech.com",
"role": "user",
"createdAt": "2018-08-21T00:29:31.441Z"
}
]
Creates a new user
Field | Description |
---|---|
user
object
|
A User Object with no id field |
Field | Description |
---|---|
user
object
|
See User Object |
curl https://api.initech.com/v1/users \
-X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer xxx.xxx.xxx' \
-d '{
"email": "lumbergh@initech.com",
"password": "ThatWouldBGreat",
"name": "Bill Lumbergh",
"role": "user"
}'
{
"id": "5b7d5a88aa7a77c62e6b3959",
"name": "Bill Lumbergh",
"email": "lumbergh@initech.com",
"role": "user",
"createdAt": "2018-08-22T12:43:52.121Z"
}
Get the user profile of the current logged in user
Field | Description |
---|---|
user
object
|
See User Object |
curl https://api.initech.com/v1/users/profile \
-X GET \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer xxx.xxx.xxx'
{
"id": "5b7c20b3aa7a77c62e6b3955",
"email": "milton@initech.com",
"role": "admin",
"createdAt": "2018-08-21T14:24:51.761Z"
}
Get specified user
Field | Description |
---|---|
id
string,url param
|
The user's id |
Field | Description |
---|---|
user
object
|
See User Object |
curl https://api.initech.com/v1/users/5b7c20b3aa7a77c62e6b3955 \
-X GET \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer xxx.xxx.xxx'
{
"id": "5b7c20b3aa7a77c62e6b3955",
"email": "milton@initech.com",
"role": "admin",
"createdAt": "2018-08-21T14:24:51.761Z"
}
Replace the specified user
Field | Description |
---|---|
id
string,url param
|
The user's id |
Field | Description |
---|---|
user
object
|
See User Object |
curl https://api.initech.com/v1/users/5b7b5ceb7873fabfe7829c25 \
-X PUT \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer xxx.xxx.xxx' \
-d '{
"email": "bobs@initech.com",
"password": "WhatWouldUSayUDoHere",
"name": "Bobs",
"role": "user"
}'
{
"id": "5b7b5ceb7873fabfe7829c25",
"name": "Bobs",
"email": "bobs@initech.com",
"role": "user",
"createdAt": "2018-08-21T00:29:31.441Z"
}
Update some or all of the fields for the specified user
Field | Description |
---|---|
id
string,url param
|
The user's id |
Field | Description |
---|---|
user
object
|
See User Object |
curl https://api.initech.com/v1/users/5b7b5ceb7873fabfe7829c25 \
-X PATCH \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer xxx.xxx.xxx' \
-d '{
"email": "bob.slydell@initech.com",
"name": "Bob Slydell"
}'
{
"id": "5b7b5ceb7873fabfe7829c25",
"name": "Bob Slydell",
"email": "bob.slydell@initech.com",
"role": "user",
"createdAt": "2018-08-21T00:29:31.441Z"
}
Delete the specified user
Field | Description |
---|---|
id
string,url param
|
The user's id |
curl https://api.initech.com/v1/users/5b7b5ceb7873fabfe7829c25 \
-X DELETE \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer xxx.xxx.xxx'