apiServer

command module
v0.1.2-0...-91d3b02 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: MIT Imports: 1 Imported by: 0

README

API server

Go Report Card

RESTful API using go, cobra CLI, gorilla mux, Basic Auth, JWT Auth

API Endpoints

Endpoint Function Method StatusCode Auth
/api/login LogIn POST Success - StatusOK, Failure - StatusUnauthorized Basic
/api/users GetUsers GET Success - StatusOK JWT
/api/user/{id} GetUser GET Success - StatusOK, Failure - StatusNoContent JWT
/api/user/{id} AddUser POST Success - StatusCreated, Failure - StatusConflict JWT
/api/user/{id} UpdateUser PUT Success - StatusCreated, Failure - StatusNoContent JWT
/api/user/{id} DeleteUser DELETE Success - StatusOK, Failure - StatusNoContent JWT

Installation

  • go install github.com/sakiib/apiServer

CLI Commands:

  • help with the start commands apiServer start -h or apiServer start --help
  • start the API server on the given port (def: 8080) apiServer start --port=8080
  • start the API server with no auth required flag (def: auth required): apiServer start --auth=false

Set Environment variables for Basic Authentication export username=sakib export password=12345


Data Model

package model

type Movie struct {
	ID     string `json:"id"`
	Title  string `json:"title"`
	Genre  string `json:"genre"`
	Rating int    `json:"rating"`
}

package model

type User struct {
	ID              string  `json:"id"`
	FirstName       string  `json:"firstname"`
	LastName        string  `json:"lastname"`
	FavouriteMovies []Movie `json:"favouriteMovies"`
}


Authentication Method

  • Basic Authentication
  • JWT Authentication (ToDo)

Testing the API Endpoints

  • Primary API endpoints testing using Postman
  • E2E Testing.
    • modlues used: net/http/httptest, testing, bytes, encoding/json, net/http.
    • Checks for the response Status Code against the Expected Status Code.

Resources:

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