Git Product home page Git Product logo

simplerestfulapi's Introduction

A simple API

Used for a basic intro to RESTful API servers in Golang as part of the Women Who Go Utah Meetup. This API features a mock database in the form of a slice of Person objects, and contains no middleware, security, or Swagger documentation. It is a very basic starting point to begin learning more about these topics.

The code used here is heavily based on the code created by Nic Raboy, and is sourced from his article Create A Simple RESTful API With Golang. All credit for the endpoints created herein goes to him. Please check out his article for more insight on how to use this code!

To run this mock api, clone the repository into your gopath src folder (ie /home/username/go/src), and from within the cloned repository, run the command go run main.go.

If you run into errors running the cloned repository, most likely your issue is that Gorilla Mux is not in your gopath. This can be resolved with either the command go get github.com/gorilla/mux or the command go get -d ./..., which tells go to recursively download all the 3rd party dependencies required by your code. Make sure to go build or go install after getting these dependencies!

You can use a tool like Postman, Insomnia, or cURL to test all the endpoints in this code. The GET endpoints can be tested through a web browser - for example, the GetAttendees endpoint can be viewed at localhost:12345/attendees

For more information on how to create HTTP endpoints in Go, check out Go by Example, which covers how to create HTTP servers and clients without a 3rd party package like Gorilla Mux. You may also find their JSON examples useful.

Other Useful Resources/Topics of Study:

Using Postman to troubleshoot RESTful APIS Go Walkthrough - JSON - This briefly covers the difference between JSON marshalling and JSON encoding/decoding. It is general practice to use an encoder/decoder when dealing with HTTP requests, as in this mock API. Encoding/JSON package - Helpful documentation on the encoding/json golang package, along with examples on how to use it. Focus on the Decoder and Encoder to understand the mock API given here. Gorilla Mux- Covers the improvements to the basic Go HTTP package that mux provides, as well as how to use mux to create your own APIs. What is REST? What is CRUD?

Good luck, and welcome to the exciting world of Web APIs (Application Programming Interfaces)!

simplerestfulapi's People

Contributors

taetem 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.