Categorygithub.com/sakiib/apiServer
modulepackage
0.1.1
Repository: https://github.com/sakiib/apiserver.git
Documentation: pkg.go.dev

# README

API server

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


API Endpoints

EndpointFunctionMethodStatusCode
/api/usersGetUsersGETSuccess - StatusOK
/api/user/{id}GetUserGETSuccess - StatusOK, Failure - StatusNoContent
/api/user/{id}AddUserPOSTSuccess - StatusCreated, Failure - StatusConflict
/api/user/{id}UpdateUserPUTSuccess - StatusCreated, Failure - StatusNoContent
/api/user/{id}DeleteUserDELETESuccess - StatusOK, Failure - StatusNoContent

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


User Data Model

type User struct {
	ID        string `json:"id"`
	FirstName string `json:"firstname"`
	LastName  string `json:"lastname"`
}

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:

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author