Coder Social home page Coder Social logo

apiserver's Introduction

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:

apiserver's People

Contributors

sakiib avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

apiserver's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.