- The Book API Server provides endpoints to create, show, read, update & delete users and books.
$ git clone [email protected]:Imtiaz246/Book-Server.git
$ cd Book-Server
$ go mod download
& echo -e "ADMIN_USERNAME=\nADMIN_PASSWORD=\nJWT_SECRET_KEY=\n" > .env
ADMIN_USERNAME=
ADMIN_PASSWORD=
JWT_SECRET_KEY=
$ go build -o main
$ ./main --port=3000
$ go test ./...
[test the API endpoints]
./main version
$ docker volume create bs-backup
[creates a volume for backup]
$ docker build -t book-server-img .
$ docker run -p 3000:3000 -v bs-backup:/root/BackupFiles --name bookserver book-server-img
$ docker pull imtiazcho/book-server:latest
Method | API Endpoint | Authentication Type | Payload | Description |
---|---|---|---|---|
POST |
/api/v1/ping |
Checks the server health | ||
POST |
/api/v1/users/token |
payload |
Returns jwt token in response | |
POST |
/api/v1/users |
payload |
Creates a user if the user information is valid | |
GET |
/api/v1/users |
Returns the list of all user | ||
GET |
/api/v1/users/{username}/books |
Returns the book list of a specific user | ||
GET |
/api/v1/users/{username} |
Returns the user specified by {username} |
||
DELETE |
/api/v1/users/{username} |
JWT |
payload |
Deletes the user specified by {username} |
PUT |
/api/v1/users/{username} |
JWT |
payload |
Updates the user information specified by {username} |
POST |
/api/v1/books |
JWT |
payload |
Creates a books if the book information is valid |
GET |
/api/v1/books |
Returns all the book list | ||
GET |
/api/v1/books/{id} |
Returns the book specified by the {id} |
||
DELETE |
/api/v1/books/{id} |
JWT |
Deletes the book specified by the {id} |
|
PUT |
/api/v1/books/{id} |
JWT |
payload |
Updates the book information specified by {id} |
- Create a user
curl -v -H "Content-type: application/json" -X POST -d '{"username":"lakkas", "password":"1234", "organization":"Appscode Ltd", "email": "[email protected]"}' http://localhost:3000/api/v1/users
- Get all user list
curl -v -H "Content-type: application/json" http://localhost:3000/api/v1/users
- Get book list of a user
curl -v -H "Content-type: application/json" http://localhost:3000/api/v1/users/{usrname}/books
- Get a user by username
curl -v -H "Content-type: application/json" http://localhost:3000/api/v1/users/{username}
- Delete a user by username
curl -v -H "Content-type: application/json" -H "Authorization: Bearer <jwt token>" -X DELETE http://localhost:3000/api/v1/users/{username}
- Update a user by username
curl -v -H "Content-type: application/json" -H "Authorization: Bearer <jwt token>" -d '{ "username" : "lakkas updated", "password" : "1234", "organization" : "Appscode Ltd", "email": "[email protected]" }' -X PUT http://localhost:3000/api/v1/users/{username}
- Create a book
curl -v -H "Content-type: application/json" -H "Authorization: Bearer <jwt token>" -X POST -d '{ "book-name": "new book", "price": 200, "isbn": "4323-6456-4756-4564", "authors": [ { "username": "admin" } ], "book-content": { "over-view": "overview", "chapters": [ { "chapter-title": "chapter 1", "chapter-content": "chapter 1 content" }, { "chapter-title": "chapter 2", "chapter-content": "chapter 2 content" } ] } }' http://localhost:3000/api/v1/books`
- Get all book list
curl -v -H "Content-type: application/json" http://localhost:3000/api/v1/books
- Get a book by book-id
curl -v -H "Content-type: application/json" http://localhost:3000/api/v1/books/{id}
- Delete a book by book-id
curl -v -H "Content-type: application/json" -H "Authorization: Bearer <jwt token>" -X DELETE http://localhost:3000/api/v1/books/{id}
- Update a book by book-id
curl -v -H "Content-type: application/json" -H "Authorization: Bearer <jwt token>" -X PUT -d '{ "book-name": "updated book curl", "price": 200, "isbn": "4323-6456-4756-4564", "authors": [ { "username": "admin" } ], "book-content": { "over-view": "overview", "chapters": [ { "chapter-title": "chapter 1", "chapter-content": "chapter 1 content" }, { "chapter-title": "chapter 2", "chapter-content": "chapter 2 content" } ] } }' http://localhost:3000/api/v1/books/{id}
- Get a jwt token
curl -v -H "Content-type: application/json" -d '{ "username": "admin", "password": "1234" }' http://localhost:3000/api/v1/users/get-token`
- Check the server health
curl -v -H "Content-type: application/json" http://localhost:3000/api/v1/ping