Projects‎ > ‎

REST API in Go

Make a Go web server which provides a "RESTful" web API for accessing and modifying server-side data.

Your server should provide access to at least 3 server-side resource collections.  One of the collections must store resources of type Student:

type Student struct {
  Name string
  Pawprint string
}

var students = make(map[string]Student)


Initialize some objects with data of your choosing.  Additionally, add a Student object with your information for grading purposes:


students["me"] = Student{"Ryanne Dolan", "rtdmr6"}


Then provide access to these objects in JSON format at appropriate request paths, such that:

GET /students/me HTTP/1.1

...returns:

{"Name":"Ryanne Dolan", "Pawprint":"rtdmr6", "VM":41}

Additionally, you should accept information via the PUT method, such that:

PUT /pets/geddy HTTP/1.1
Content-Length: 34

{"Species":"Dog", "Color":"Black and Tan"}

...would actually change or create the corresponding object on the server.

Finally, you must handle GET requests for each entire collection, such that 

GET /students HTTP/1.1

returns something like...

{"me":  {"Name":"Ryanne Dolan", "Pawprint":"rtdmr6", "VM":41},
 "bob": {"Name":"Bob", "Pawprint":"abcdef", "VM":100}
}

Make sure the following URIs work:
  1. / : directory listing
  2. /<yourcode.go> :  your source file
  3. /students/me : your name etc in JSON
  4. /<collection>: a collection of resources
  5. /<collection>/<id>: a specific resource
To test your server, you can use client-side JavaScript that GETs and PUTs JSON to your server.  We'll talk about how to do this in class (a lot!).


Here's an example of a similar API:
Comments