Endpoints Specification
Authentication Header
You can read the authentication header from the headers of the request
Authorization: Token jwt.token.here
Auth Endpoints
Login
POST /api/auth/login
No authentication required.
Required body fields: email
, password
Example request body:
{
"data": {
"email": "vedran@badun.com",
"password": "soksak"
}
}
Example response:
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJyb2tvLmxhYnJvdmljQGdtYWlsLmNvbSIsInNjb3BlcyI6WyJ1c2VyIl0sImlhdCI6MTY3Nzg1NTc2NywiZXhwIjoxNjc3ODYyOTY3fQ.pf__pJLDLGVyLIqlt14ng53v3cotdJgeig3hbtBncsw"
}
Registration
POST /api/auth/register
No authentication required.
Required body fields: email
, firstName
, lastName
, password
Example request body:
{
"data": {
"email": "vedran@badun.com",
"firstName": "Vedran",
"lastName": "Badun",
"password": "soksak"
}
}
Example response:
{
"data": {
"id": 1,
"email": "vedran@badun.com",
"firstName": "Vedran",
"lastName": "Badun",
"role": "user",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJyb2tvLmxhYnJvdmljQGdtYWlsLmNvbSIsInNjb3BlcyI6WyJ1c2VyIl0sImlhdCI6MTY3Nzg1NTc0OCwiZXhwIjoxNjc3ODYyOTQ4fQ.HMrfNvCiZtLDWHqwWzK3aGNdAk6L1RppKYLb4wQWaS8"
}
}
User Endpoints
Get Users
GET /api/users
Authentication required.
Query params to filter result:
?search=Vedran
- search userfirstName
|lastName
|email
,?perPage=5
- number of items to return per page (default 10),?page=2
- get specific page (default 1).
Example request:
GET /api/users?perPage=5&search=Vedran
Example response:
{
"status": 200,
"message": "Success",
"meta": {
"from": 1,
"to": 5,
"page": 1,
"perPage": 5,
"total": 10,
"prev": false,
"next": true,
"last": 2
},
"data": [
...
{
"id": 1,
"firstName": "Vedran",
"lastName": "Badun",
"birth": "1949-08-30T22:14:49.165Z"
},
...
]
}
Get User
GET /api/users/:id
Authentication required.
Example request: GET /api/users/1
Example response:
{
"status": 200,
"data": {
"id": 1,
"firstName": "Vedran",
"lastName": "Badun",
"birth": "1949-08-30T22:14:49.165Z"
}
}
Delete User
DELETE /api/users/:id
Authentication required.
Example request: DELETE /api/users/10
Example response:
{
"status": 200,
"message": "User deleted"
}
Update User
PATCH /api/users/:id
Authentication required.
Example request body:
{
"firstName": "Vedran",
"lastName": "Badun",
"email": "vedran.badun@gmail.com",
"role": "user"
}
Example response:
{
"status": 200,
"message": "User updated",
"data": {
"id": 2,
"firstName": "Vedran",
"lastName": "Badun",
"email": "vedran.badun@gmail.com",
"role": "user"
}
}
Author Endpoints
Get Authors
GET /api/authors
Authentication required.
Optional query params:
?search=Kole
- search authorsfirstName
orlastName
,?startDate=1900-01-01
- query authors bydateBirth
range,?endDate=1950-01-01
- query authors bydateBirth
range?perPage=5
- number of items to return per page (default 10),?page=1
- get specific page (default 1).
Example request:
GET /api/authors?perPage=5&search=Kole
Example response:
{
"status": 200,
"message": "Success",
"meta": {
"from": 1,
"to": 5,
"page": 1,
"perPage": 5,
"total": 10,
"prev": false,
"next": true,
"last": 2
},
"data": [
...
{
"id": 1,
"firstName": "Kole",
"lastName": "Okuneva",
"birth": "1949-08-30T22:14:49.165Z"
},
...
]
}
Get Author
GET /api/authors/:id
Authentication required.
Example response:
{
"status": 200,
"data": {
"id": 1,
"firstName": "Kole",
"lastName": "Okuneva",
"birth": "1949-08-30T22:14:49.165Z"
}
}
Get Author Books
GET /api/authors/:id/books
Authentication required.
Example response:
{
"status": 200,
"data": [
...
{
"id": 15,
"title": "Some book title",
"isbn": "978-3-16-148410-0",
"authorId": 1
},
...
]
}
Create Author
DELETE /api/authors
Authentication required.
Example body request:
{
"firstName": "Vedran",
"lastName": "Badun",
"birth": "1980-01-01T00:00:00"
}
Example response:
{
"status": 201,
"message": "Created",
"data": {
"id": 11,
"firstName": "Vedran",
"lastName": "Badun",
"birth": "1980-01-01T00:00:00"
}
}
Delete Author
DELETE /api/authors/:id
Authentication required.
Example request: DELETE /api/authors/10
Example response:
{
"status": 200,
"message": "Author deleted"
}
Update Author
PATCH /api/authors/:id
Authentication required.
Example request body:
{
"firstName": "Vedran",
"lastName": "Badun",
"dateBirth": "1952-04-21T19:15:04.207Z"
}
Example response:
{
"status": 200,
"message": "Author updated",
"data": {
"id": 2,
"firstName": "Vedran",
"lastName": "Badun",
"birth": "1952-04-21T19:15:04.207Z"
}
}
Books Endpoints
Get Books
GET /api/books
Authentication required.
Optional query params:
?title=Kole
- search booktitle
orisbn
,?perPage=5
- number of items to return per page (default 10),?page=1
- get specific page (default 1).
Example request:
GET /api/books?perPage=5&search=New
Example response:
{
"status": 200,
"message": "Success",
"meta": {
"from": 1,
"to": 5,
"page": 1,
"perPage": 5,
"total": 10,
"prev": false,
"next": true,
"last": 2
},
"data": [
...
{
"id": 1,
"title": "Brave New World",
"isbn": "586cf6fb-103b-4a19-b275-08c718bbc8df",
"authorId": 7
},
...
]
}
Get Book
GET /api/books/:id
Authentication required.
Example response:
{
"status": 200,
"message": "Success",
"data": [
...
{
"id": 15,
"title": "Brave New World",
"isbn": "978-3-16-148410-0",
"authorId": 1
},
...
]
}
Create Book
POST /api/books
Authentication required.
Example body request:
{
"title": "Vlak u Snijegu",
"isbn": "978-3-16-148410-0",
"authorId": 3
}
Example response:
{
"status": 201,
"message": "Created",
"data": {
"id": 11,
"title": "Vlak u Snijegu",
"isbn": "978-3-16-148410-0",
"authorId": 3
}
}
Delete Book
DELETE /api/books/:id
Authentication required.
Example request: DELETE /api/books/10
Example response:
{
"status": 200,
"message": "Book deleted"
}
Update Book
PATCH /api/books/:id
Authentication required. Example request body:
{
"title": "Vlak u Snijegu",
"isbn": "978-3-16-148410-0"
}
Example response:
{
"status": 200,
"message": "Book updated",
"data": {
"id": 2,
"title": "Vlak u Snijegu",
"isbn": "978-3-16-148410-0",
"authorId": 9
}
}