Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sstarcher/simple-http
https://github.com/sstarcher/simple-http
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/sstarcher/simple-http
- Owner: sstarcher
- Created: 2019-05-13T22:36:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-05-13T22:47:23.000Z (over 5 years ago)
- Last Synced: 2023-05-26T00:33:40.365Z (over 1 year ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Golang HTTP Server
Runs a simple golang http server on port 8080. Responds to requests with `Hello, World`, but when the `Accept` header specifies `application/json` as supported it will respond with a json formatted message that says `Good Morning`. If the `-debug` parameter is specified it will log each request URL.
## Prerequisites
* Golang 1.12.4 - https://golang.org/doc/install
* Curl## Setup instructions, including instructions on how to install prerequisite packages
* `go get github.com/sstarcher/simple-http`
* `cd $GOPATH/src/github.com/sstarcher/simple-http`
* `GO111MODULE=on go mod vendor`## A command to start the application
* `go run .`## A command to run the unit tests for your application
* `go test ./...`## Options
* `-debug` - Will enable debug logging and output each request## Tests
* Non-json responses of `Hello, World
`
* `curl 'http://localhost:8080'`
* `curl 'http://localhost:8080/'`
* `curl -H 'Accept: bob' 'http://localhost:8080'`
* Json responses of `{"message": "Good Morning"}`
* `curl -H 'Accept: application/json' 'http://localhost:8080'`
* `curl -H 'Accept: application/json,text/html' 'http://localhost:8080'`
* `curl -H 'Accept: text/html,application/json' 'http://localhost:8080'`
* Empty responses
* `curl 'http://localhost:8080/blah/other?and=things&other=stuff'`
* `curl -H 'Accept: application/json' 'http://localhost:8080/blah/other?and=things&other=stuff'`
* `curl 'http://localhost:8080/blah/other?and=things&other=stuff'`## Assumptions
* GET and POST methods are both accepted. POST is not specified as to what it should do so it's blank.
* GET method only returns data on `/` and is ignored with any parameters.
* Debug logging should happen on all HTTP methods not just GET.
* When `application/json` is specified as one of the `Accept` headers we respond with json. We behave the same way if multiple comma seperated `Accept` headers are specified.