Week 4 - Overview
Students should be comfortable with the following at the end of this week:
- HTTP Verbs and Parameters
- Consuming APIs
- Creating APIs
- Rails Fundamentals
- Routing and Controllers
Important Links
Monday - The Web and APIs
Challenge: Inheritance
Problem of the Day: Employee and Department API
- Human Learning:
- Scarring with age/experience
- Good scarring example: Saving hardest things for last sucks
- Bad scarring example: Given one bad experience, some people assume that Millenials are all lazy.
- Bad scarring example: Taking risks on products costs too much money.
- DIAGRAM: Topological map of scarring
- ON BOARD: Be aware of your scarring
- Web Basics
- Web Addresses
- The Parts of a URL
- Parameters
- What is an API?
- On the web, what sort of data do we get back from APIs?
- XML
- JSON
- CSV
- Images
- The broad notion of APIs:
- HTTParty
- API without logging in
- https://api.github.com/users/masonfmatthews/events
- API Keys
- http://www.wunderground.com/weather/api/
- Keeping keys and passwords out of committed code (using ENV)
- Stubbing/Mocking
- User Input
- API Calls
- Time-based Results
Lecture Notes/Links
Evening Reading
Assignment
Weather Report
Tuesday - Rails and the Web
Challenge: Composition
Problem of the Day: Folder Structure
- Example: Begin work on yesterday’s Employee and Department API
- The Web
- IP addresses
- Ports
- Request/Response
- Servers
- Rails Introduction
rails new
bin/rails server
- Rails folder structure
- MVC
bin/rails generate model
bin/rake db:migrate
bin/rails generate migration
bin/rails console
bin/rails generate controller
- Unit Testing in Rails
Lecture Notes/Links
Evening Reading
Assignment
Get a start on Create a Voting API:
- Review the requirements and create an ERD
- Create a new Rails app
- Create migrations and models as needed
- Add associations and validations
- Push to GitHub
- Create at least two unit tests for each model
- Make sure that you can run
rake
successfully to run the tests
- Make sure that you can run
rails server
and see the default page in your browser
- Create the
candidates
controller with index
, show
, and create
actions.
- Make the index action return a JSON representation of all the candidates.
- Make the show action return the first candidate.
- Make the create action create a new candidate (in the database). It can have any properties for now.
- Make sure that you can access it in your browser
- Create
- Delete
README.rdoc
and make your own (filled in) README.md
- Push to GitHub
- Create an estimate for the number of hours you expect to need to complete this assignment tomorrow night
If you anticipate getting to hard or nightmare modes, read those modes before beginning work tonight and take those requirements into account in your models and migrations.
Wednesday - Controllers and the Router
Challenge: Enumerable
Problem of the Day: Model to JSON
- Human Learning:
- ON BOARD: Retrieve rather than re-expose
- Random Topics:
rake db:rollback
rake db:drop
- Explore Rails’ Gemfile
- Example: Continue work on Monday’s Employee and Department API
respond_to
in the controller
- HTML Verbs
- GET (google.com)
- POST (coursyl.com)
- PATCH
- DELETE
- Postman
- The Router
- Controllers
- Controller Testing
Lecture Notes/Links
Evening Reading
Assignment
Create a Voting API. After you’re done, reflect on your estimate from last night.
- In theory, your estimate should be better now that you’ve gotten part of the way through the project.
- Document your number of hours worked at the end.
Thursday - Serializers, Data
Challenge: Include
Problem of the Day: Assorted JSON
- Example: Continue work on Monday’s Employee and Department API
- Fixtures
- Seeds
- Views and Controller Instance Variables
- Callbacks
- JBuilder
json.name @candidate.name
json.extract! @candidate, :id, :name, :party
json.array! @candidates, :id, :name, :party
- Non-ActiveRecord Models (don’t
generate
!)
Lecture Notes/Links
Evening Reading
- Router
rake routes
- Level 1 - we know this.
- Level 2 - Naming addresses in a more custom way
- Level 3 - Putting
id
s (or other params
) in paths
- Different kinds of API auth
- Gems for accessing APIs
- Token Auth in params
- Token Auth in headers
- Basic Auth (not so good)
- OAuth - later
- Testing Validations - not as important as I let on.
Lecture Notes/Links
Assignment - IN PAIRS
Build Your Own API