-
-
Save dwayne/9902605 to your computer and use it in GitHub Desktop.
http://railsapis.codeschool.com/levels/1/challenges/1
Topics
- REST
- Routes
- Constraints
- Namespaces
REST stands for REpresentational State Transfer.
By following a strict set of operations, REST allows building an infrastructure that can support different types of applications.
The rake routes
command lists all the routes, URIs, controller#actions, and URL helpers available on our app.
Tip: You can use with_options
to factor duplication out of options passed to a series of method calls.
Resources
You can use constraints to enforce a subdomain. Keeping our API under its own subdomain allows load balancing traffic at the DNS level.
Using Subdomains in Development
resources :posts, constraints: { subdomain: 'api' }
resources :comments, constraints: { subdomain: 'api' }
Edit the /etc/hosts
file. For example:
127.0.0.1 my-app-dev.com
127.0.0.1 api.my-app-dev.com
This would then map to:
Resources
Tip: You can pass a constraints
option to the namespace
method.
Resources
This is a sweet tip.
If we want to write an acronym in the traditional ALL CAPS then Rails inflections can help us out.
# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'API'
end
Resources