A REST API built with go, that allows you to read and add rollercoaster data.
-
Make sure you have Go 1.16 installed
-
Set the environment variable "ADMIN_PASSWORD=secret"
-
Run the main function in the 'server.go' file
- /costers -> shows all rollercoaster data
Use the following query parameters to filter the rollercoaster:- name: name of the rollercoaster
- park: park where the rollercoaster is located
- height: height of the rollercoaster
- minHeight: minimum height of the rollercoaster
- maxHeight: maximum height of the rollercoaster
- manufacturer: manufacturer of the rollercoaster
- /coasters/<id> -> show rollercoaster data for specific id
- /addCoaster -> add a rollercoaster
- /admin -> login to see the super secret admin page
- /costers -> shows all rollercoaster data
- Go
- Go http package
This project was created following kubucation's video on YouTube.
You can find it here: https://www.youtube.com/watch?v=2v11Ym6Ct9Q&ab_channel=kubucation
Functionality I added includes:
- Refactored code and created handlers folder for improved readability
- "/" redirects to "/coasters" and anything else gets "page not found" html as a response
- Add "WWW-Authenticate: Basic" header to the response in case of wrong login credentials for "/admin"
- Show form under "/addCoaster" to add a coaster from the browser
- WIP: added filter for the "/coasters" route via query parameters
You can also use the browser to test the routes
curl -v localhost:8080/coasters -X POST -d '{"name": "Taron", "inPark": "Phantasialand", "height": 30, "manufacturer": "Intamin"}' -H "Content-Type: application/json"
curl -v localhost:8080/coasters | jq
curl localhost:8080/coasters/random -L
curl localhost:8080/admin -u admin:secret