Ahasannn / book-server-api

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

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

License:MIT License


Languages

Language:Go 100.0%