Exercise Monday

Goal: Build and test your own API. Once you’ve completed the basic functionality for your API, go to the upcoming Further Exploration with Rails APIs lesson for further API-building objectives.

Warm Up


Discuss possible answers to these common Ruby-specific interview questions. You can format this as a mock interview or brainstorm answers as a team:

  • What makes Ruby an object-oriented programming language?
  • What is a Gem? What are some of your favorite Gems and why?
  • What is the difference between a class and instance variable? When is each used?
  • What is the difference between a public and private method?
  • What is self in Ruby? Where might we use it?

Code


Building Your Own API

You may work on this project with a pair for the entire course section or split the course section into two projects: two 2-day projects for full-time students and two week-long projects for part-time students.

For the first half of the section, you'll build your own API. Make sure you use request specs to test all routes and exceptions. You should also use Postman or cURL to manually test your calls.

For the second half of the section, you'll build an application that communicates with one of the APIs either you or your peers built in class during the first half of the course section. You’ll also continue to build out and refactor the API you're working with. As you build your user stories, keep in mind that your primary API users will be developers implementing the API into their own applications.

On short weeks, you'll spend most of your time on building out the API and pursuing further exploration. For full-time students, at least one class will be set aside for building an application that communicates with your API. For part-time students, at least 2 classes will be set aside for building an application that communicates with your API.

Code


Travel API

Build an API that allows users to GET and POST reviews about various travel destinations around the world. Here are some user stories to get started.

  • As a user, I want to GET and POST reviews about travel destinations.
  • As a user, I want to GET reviews by country or city.
  • As a user, I want to see the most popular travel destinations by number of reviews or by overall rating.
  • As a user, I want to PUT and DELETE reviews, but only if I wrote them. (Start by requiring a user_name param to match the user_name of the author on the message. You can always try authentication later.)
  • As a user, I want to look up random destinations just for fun.

Message Board API

Create a message board service that can be accessed via your API. Users should be able to GET and POST messages for specific message boards.

  • As a user, I want to be able to GET all messages related to a specific group.
  • As a user, I want to be able to POST messages to a specific group.
  • As a user, I want to be able to see a list of all groups.
  • As a user, I want to input date parameters and retrieve only messages posted during that timeframe.
  • As a user, I want to be able to PUT and DELETE messages, but only if I wrote them. (Start by requiring a user_name param to match the user_name of the author on the message. You can always try authentication later.)

API of Choice

APIs aren't just used for data interaction and manipulation. They can also be used for computation as well. Build a database-centered or computation API around an area of interest to you. Make sure you write your own user stories first.

Further Exploration

Go to the upcoming Further Exploration with Rails APIs lesson for further API-building objectives.

Peer Code Review


  • Application successfully returns responses for each API call.
  • Application handles exceptions.
  • Application includes custom routes and model scopes.
  • All routes are tested with request specs.
  • README thoroughly describes all endpoints along with parameters that can be used.
  • Application works as expected.
  • Project is in a presentable, portfolio-quality state.
  • Project demonstrates understanding of all concepts covered in this course section. If prompted, you can discuss your application using the correct terminology.

Lesson 13 of 19
Last updated more than 3 months ago.