Giter Club home page Giter Club logo

go-rollercoaster-api's Introduction

go-rollercoaster-api

What is it and what does it do?

A REST API built with go, that allows you to read and add rollercoaster data.

How to use it?

  1. Make sure you have Go 1.16 installed

  2. Set the environment variable "ADMIN_PASSWORD=secret"

  3. Run the main function in the 'server.go' file

    Routes

    • /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

What did I learn?

  • Go
  • Go http package

Disclaimers

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

Curl commands for testing the API

You can also use the browser to test the routes

Post Data:

curl -v localhost:8080/coasters -X POST -d '{"name": "Taron", "inPark": "Phantasialand", "height": 30, "manufacturer": "Intamin"}' -H "Content-Type: application/json"

Get Data:

curl -v localhost:8080/coasters | jq

Get Random Coaster (with redirect):

curl localhost:8080/coasters/random -L

Test Authentication

curl localhost:8080/admin -u admin:secret

go-rollercoaster-api's People

Contributors

lucas-carvajal avatar

Watchers

 avatar  avatar

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.