book-server-api

command module
v0.0.0-...-7470c0e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2022 License: MIT Imports: 1 Imported by: 0

README

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

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL