Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sakiib/apiserver
https://github.com/sakiib/apiserver
basic-authentication cli cobra go golang helm-charts jwt-authentication
Last synced: 16 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/sakiib/apiserver
- Owner: sakiib
- License: mit
- Created: 2020-12-14T05:37:28.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-17T12:14:58.000Z (almost 4 years ago)
- Last Synced: 2024-11-08T21:47:21.401Z (2 months ago)
- Topics: basic-authentication, cli, cobra, go, golang, helm-charts, jwt-authentication
- Language: Go
- Homepage:
- Size: 1.6 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# API server
[![Go Report Card](https://goreportcard.com/badge/github.com/sakiib/apiServer)](https://goreportcard.com/report/github.com/sakiib/apiServer)
### RESTful API using [go](https://github.com/golang), [cobra CLI](https://github.com/spf13/cobra), [gorilla mux](https://github.com/gorilla/mux), Basic Auth, [JWT Auth](https://github.com/dgrijalva/jwt-go)
---
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 modeltype Movie struct {
ID string `json:"id"`
Title string `json:"title"`
Genre string `json:"genre"`
Rating int `json:"rating"`
}```
```
package modeltype 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](https://github.com/postmanlabs)
* 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:
* [sysdevbd learn GO](https://sysdevbd.com/go/)
* [Encoding & Decoding JSON](https://kevin.burke.dev/kevin/golang-json-http/)
* [A Beginner’s Guide to HTTP and REST](https://code.tutsplus.com/tutorials/a-beginners-guide-to-http-and-rest--net-16340)
* [HTTP Response Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
* [TutorialEdge Creating A Simple Web Server with Golang](https://tutorialedge.net/golang/creating-simple-web-server-with-golang/)