Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/technicallyjosh/go-api-example
Example of a go API
https://github.com/technicallyjosh/go-api-example
Last synced: about 1 month ago
JSON representation
Example of a go API
- Host: GitHub
- URL: https://github.com/technicallyjosh/go-api-example
- Owner: technicallyjosh
- Created: 2020-06-18T22:51:21.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-19T16:04:54.000Z (over 4 years ago)
- Last Synced: 2023-02-26T18:56:21.606Z (almost 2 years ago)
- Language: Go
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-api-example
Example of a go API with a password validation endpoint and tests. The service runs on port 8000.
The correct credentials are:
**username**: technicallyjosh
**password**: testing123## Dependencies
- [Go 1.14+](https://golang.org/doc/install)
## Local
**Install Dependencies**
```console
$ go mod download
```**Build and Run**
```console
$ go build && ./go-api-example
```**Run**
```console
$ go run .
```**Test**
```console
$ go test
```## In Docker
**Build**
```console
$ docker build -t go-api-example .
```**Run server**
```console
$ docker run --rm -p 8000:8000 go-api-example
```## Running Tests
**Local**
```console
$ go mod download
$ go test
```**Docker**
```console
$ docker run --rm go-api-example /bin/bash -c "go test"
```## Routes
### `PUT /users/verify`
Verifies a password for a user. In this example it's more like a login without assigning a token or
session etc... Normally when just _verifying_ a user's password, we'd accept a signed token in the
header and get the username or id from it.#### Request Body (JSON)
| Property | Type | Required |
| -------- | -------- | -------- |
| username | `string` | Yes |
| password | `string` | Yes |#### Example
```console
$ curl -i -XPUT localhost:8000/users/verify -d '
{
"username": "technicallyjosh",
"password": "testing123"
}'; echo
```