Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ahasannn/book-server-api

It is a RESTful book server api implemented in Go to handle list of books.
https://github.com/ahasannn/book-server-api

api basic-authentication crud-operation golang gorilla-mux json jwt-authentication postman rest

Last synced: about 1 month ago
JSON representation

It is a RESTful book server api implemented in Go to handle list of books.

Awesome Lists containing this project

README

        

# Book Sever

It is a RESTful API using [Go](https://github.com/golang), [gorilla/mux](https://github.com/gorilla/mux), [Basic Authentication](https://learningprogramming.net/golang/golang-restful-web-api/basic-authentication-in-golang-restful-web-api/), [JWT Authentication](https://github.com/dgrijalva/jwt-go).


## Brief Description

I have built a fully-fledged REST API with Go that exposes GET, POST, DELETE and PUT endpoints which allows to perform the full range of CRUD operations. A handler function accepts http response and request in json format. Then, the request is decoded and written to response according to the called function. This handler function is wrapped by the authentication middleware to perform the security check.


## API Endpoints

| URL | Function | Method | Description | Authentication Type
| ----------- | ----------- | ------ | ----------- |----------
| https://localhost:8000/api/login | Login | POST | Return JWT token in response for successful authentication | Basic
| https://localhost:8000/api/getBooks | getBooks | GET | Returns the details of all the books | JWT
| https://localhost:8000/api/getBook/{id} | getBook | GET | Returns the details of the book with the valid requested book id | JWT
| https://localhost:8000/api/createBook | createBook | POST | Creates a new book | JWT
| https://localhost:8000/api/updateBooks/{id} | updateBooks | PUT | Updates the details of the requested book id | JWT
| https://localhost:8000/api/deleteBooks/{id} | deleteBooks | DELETE | Deletes the book specified by id | JWT


## Authentication Method

- Basic Authentication
- JWT Authentication


## Data Models

type Book struct {
ID string `json:"id"`
Isbn string `json:"isbn"`
Title string `json:"title"`
Author *Author `json:"author"`
}

type Author struct {
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
}


## Installation
* go install github.com/Ahasannn/book-server-api@b687963


Set Environment variables for Basic Authentication.

export username=Ahasan
export password=ak4747


Testing the API endpoints

* Primary api endpoints can be tested with [Postman](https://www.postman.com/)


Server Run

go build -o bin/book-server-api .
./bin/book-server