This assignment will ask you to explore the concepts introduced in class and set up a data-driven API.
Brief: Iterate last week’s assignment into a web api that runs from a database to provide resources for this course
Due Date: Tuesday Nov 8, 12pm ET
Submission: Add completed code to ‘skills2’ folder in Student section of the course’s GitHub Repo.
As part of the exercise, students will:
For this project, you are to start with the web application we built last week (see week1-solution in the code repo).
Using this as a starting point, you’re going to iterate on the concepts
Using this template, create a basic web ‘api’ that will serve up information about this course to someone who might want to make use of it.
As part of this project you will be asked to add the following functionality to your Sinatra application. For all of the following use a get
request.
Basic
Hint: You’ll need to add the ‘json’ gem to your project file.
Hint you can create json easily by creating an hash object like this and using the to_json
method on it e.g.
{ name: "Some name", name_of_array: ["item 1", "item 2", "item 3"], is_it_true: false, counter: 45 }.to_json
{ status: "OK", message: "The course is called ... " }.to_json
Hint use the following to specify routes will return json at the top of your file
# before do
# content_type :json
# end
Links
Convert the ‘interesting links’ to be stored in a database. Create a table called ‘course_links’ and a model called ‘course_link’ with the following: - a column called ‘url’ (a string) that will hold the link - a column called ‘title’ (a string) that will have some descriptive information about the link. - seed the database with some initial data. - Test: adding, updating, deleting links
Update the interesting_link
method to return a result from ActiveRecord (and the Sqlite Database)
course_links
tableweeks
that contains two columns topic
(text) and beginning
(datetime)week
and course_link
define the associating using belongs_to
and has_many
week_id
and update it if it’s passedAssignments
assignments
and add a corresponding model. It should contain the following
to_json
method to your model *) that shows if the due_date has passed or not.Respond To
For every data driven element of the API, update it to respond to html (default), xml or json.
Check it using cURL
curl -v -H "Accept: text/html, */*" http://localhost:9393/tasks
curl -v -H "Accept: application/xml, */*" http://localhost:9393/tasks
curl -v -H "Accept: application/json, */*" http://localhost:9393/tasks
Advanced
Right now anyone can add, edit or delete these resources. Can you think of a simple way to secure it so that only trusted people can perform sensitive actions?
Once implemented, return an appropriate error if an unauthorised/untrusted visitor tries to access it.
Experiment
Try out some other stuff. Practice beyond these examples and add:
Each component above is graded equally. Full grade (100%) is awarded for