Home Reference Source Repository
Manual » Example

Example

In this example section you can read about the routes that are provided by Beerio API.

Index

GET - http://localhost:5000/

Gives some basic information about the server on which the API is running on.

Example output:

{
  "repo": "https://github.com/SCThijsse/beerio-api.git",
  "server": "serv01",
  "totalBeers": 564,
  "uptime": 84956,
  "version": "1.0.0",
  "commit": "2dce73e"
}

Users

POST - http://localhost:5000/register

Register a new user.

Example body:

{
  "firstname": "First Name",
  "lastname": "Last Name",
  "email": "[email protected]",
  "username": "Username",
  "password": "Password"
}

Example output:

{
  "user": {
    "_id": "Username",
    "firstname": "First Name",
    "lastname": "Last Name",
    "email": "[email protected]",
    "username": "Username",
    "password": "$2a$10$PSP.dm61vtvarDg/HBjC9.XzGryjHrxtocGNnU9CjHWdtMWmz.gZe",
    "beers": []
  },
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJVc2VybmFtZSIsInVzZXJuYW1lIjoiVXNlcm5hbWUiLCJleHAiOjE0OTIwMDcyOTMsImlhdCI6MTQ4NjgyNjg5M30.dMzBRl--fpIIuRt5Yeu1OmdXsxOzJ55NpVl0jxckZ_g"
}

POST - http://localhost:5000/login*

Login with a user.

Example body:

{
  "username": "Username",
  "password": "Password"
}

Example output:

{
  "user": {
    "_id": "Username",
    "firstname": "First Name",
    "lastname": "Last Name",
    "email": "[email protected]",
    "username": "Username",
    "password": "$2a$10$PSP.dm61vtvarDg/HBjC9.XzGryjHrxtocGNnU9CjHWdtMWmz.gZe",
    "beers": []
  },
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJVc2VybmFtZSIsInVzZXJuYW1lIjoiVXNlcm5hbWUiLCJleHAiOjE0OTIwMDcyOTMsImlhdCI6MTQ4NjgyNjg5M30.dMzBRl--fpIIuRt5Yeu1OmdXsxOzJ55NpVl0jxckZ_g"
}

GET - http://localhost:5000/users/{username}

Get a single user based on the unique username

Example header:

Authorization: Bearer <token>

Example output:

{
  "_id": "Username",
  "firstname": "First Name",
  "lastname": "Last Name",
  "email": "[email protected]",
  "username": "Username",
  "password": "Encrypted Password",
  "beers": [
    "Beer Name"
  ]
}

Beers

POST - http://localhost:5000/beers

Insert a new beer into the database.

Example header:

Authorization: Bearer <token>

Example body:

{
  "name": "Beer Name",
  "style": "Beer Style",
  "type": "Beer Type",
  "abv": 1,
  "ebu": 1,
  "thumbnail": "https://somethumbnail.com/images.png"
}

Example output:

{
  "user": "Username",
  "name": "Beer Name",
  "style": "Beer Style",
  "type": "Beer Type",
  "abv": 1,
  "ebu": 1,
  "thumbnail": "https://somethumbnail.com/images.png",
  "_id": "589de779ff7fb61d2d6817d3",
  "votes": 0
}

GET - http://localhost:5000/beers?page=1&search=beer%20name&sort=name&order=-1

Get multiple beers based on search queries.

Query Strings

 - page           # Page number, shows 25 per page.
 - search         # Search on beer name
 - sort           # Order by 'name', 'style', 'type', 'abv', 'ebu'
 - order          # -1 for ascending, 1 for descending

Example output:

[{
    "_id": "589de779ff7fb61d2d6817d3",
    "name": "Beer Name",
    "style": "Beer Style",
    "type": "Beer Type",
    "thumbnail": ""
    "abv": 1,
    "ebu": 1,
    "thumbnail": "https://somethumbnail.com/image.png"
}]

GET - http://localhost:5000/beers/{beer}

Get a single beer based on the id.

Example output:

{
  "_id": "589de779ff7fb61d2d6817d3",
  "user": "Username",
  "name": "Beer Name",
  "style": "Beer Style",
  "type": "Beer Type",
  "abv": 1,
  "ebu": 1,
  "thumbnail": "https://somethumbnail.com/image.png",
  "votes": 0
}

PUT - http://localhost:5000/beers/{beer}

Update a beer based on the id.

Example headers:

Authorization: Bearer <token>

Example body:

{
  "name": "Beer Name2",
  "style": "Beer Style",
  "type": "Beer Type",
  "abv": 1,
  "ebu": 1,
  "thumbnail": "https://somethumbnail.com/image.png"
}

Example output:

{
  "_id": "589de779ff7fb61d2d6817d3",
  "user": "Username",
  "name": "Beer Name",
  "style": "Beer Style",
  "type": "Beer Type",
  "abv": 1,
  "ebu": 1,
  "thumbnail": "https://somethumbnail.com/image.png",
  "__v": 0,
  "votes": 0
}

DELETE - http://localhost:5000/beers/{beer}

Delete a beer based on the id.

Example headers:

Authorization: Bearer <token>

Example output:

{
  "_id": "589de779ff7fb61d2d6817d3",
  "user": "Username",
  "name": "Beer Name",
  "style": "Beer Style",
  "type": "Beer Type",
  "abv": 1,
  "ebu": 1,
  "thumbnail": "https://somethumbnail.com/image.png",
  "__v": 0,
  "votes": 0
}

POST - http://localhost:5000/beers/{beer}/vote

Increase the vote value for a beer, if you have already voted for a beer, the vote will decrease.

Example headers:

Authorization: Bearer <token>

Example output:

{
  "_id": "589de779ff7fb61d2d6817d3",
  "user": "Username",
  "name": "Beer Name",
  "style": "Beer Style",
  "type": "Beer Type",
  "abv": 1,
  "ebu": 1,
  "thumbnail": "https://somethumbnail.com/image.png",
  "__v": 0,
  "votes": 0
}