This assignment will ask you to explore the concepts introduced in class and set up a basic Sinatra web service:
Brief: Build a basic web app that provides information on this course
Due Date: Tuesday Nov 1, 12pm ET
Submission: Add completed code to ‘skills1’ 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 a basic sinatra application (see template in the code repo).
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.
Root
/
return a 422 errortitle
endpoint i.e. don’t allow a response from this route (see below)Hint: Errors can be defined by using the error number as the response from the route’s block
Hint: You’ll need to define a block that handles an error e.g. error 403 do 'Access forbidden' end
Hint: You can use redirect to('/bar')
to redirect to another route in your sinatra application.
Basic
title
that returns a string that matches the full title of this coursecatalog_description
that returns a full catalog description of the courseunits
that returns the number of units of the courseinstructor
that returns the name of the instructor, email address and Slack id
Parameters and Conditions
Hint You’ll need to use conditional logic (if elsif else end statements) to make this bit work.
1) Add a configuration block and provide settings that define three links (to the course slack, the main site and the github repository). Then,
link_to
that takes one parameter named item
and that will return one of the three links.2) Add an endpoint to look up meeting times for the course.
meeting_times
that takes one parameterExplore: If you’re feeling adventurous try working with date and time objects in Ruby for this part.
Dynamic
We’ll explore some more advanced but richer ways to add some interactivity and dynamic data through date and time, conditions and arrays.
1) Create an endpoint that lets someone know if we’re in class or not.
in_session
that takes no paramtersTime.now
* to look up the time on the serverTime.new
* to create a time instance for the beginning and end of each meeting times2) Return a random link
interesting_link
that returns one of those links each time it’s calledHint: .sample
is a useful method on array that will pick an item from it at random.
User Session
For the interesting_link
, use sessions to store what links the user has already seen.
Modify the response to:
Experiment
Try out some other stuff. Practice beyond these examples and add at least two of your own end points
Each component above is graded equally. Full grade (100%) is awarded for