Skip to content

Ahasannn/book-server-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Book Sever

It is a RESTful API using Go, gorilla/mux, Basic Authentication, JWT Authentication.


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

Server Run

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

Releases

No releases published

Packages

No packages published

Languages