JSON API

Logistics

Update Profile

Make sure you check in with your TA!

If you don't have a group or a TA hasn't emailed you let us know ASAP.

API

  • Stands for Application Program Interface
  • Specifies how you interact with software
  • A layer of abstraction for other applications to interact with your Rails application
    • Usually there is documentation on input and output

JSON

  • Javascript Object Notation
  • Key Value Pairs + Arrays
  • Values can be strings, numbers, booleans, and null
  • Common way to send data to and from an API

Namespaces

  • Organization of controllers within folders allows for better organization
  • In routes.rb to specify that it's under a specific folder use the 'namespace' function
  • An example on the next slide to resource a users controller that is app/controllers/api/v1/users_controller.b
    • The matching url is 'baseurl.com/api/v1/users'

render

  • A controller method that is implicitly called
    • Assumes there is a view with the same name as the action
  • To specify JSON we just pass a 'json' option
    • Ex:
      • render json: @users
      • This will render the value stores in @users as a JSON string.

Note

  • We will disable CSRF token
    • Stands for Cross Site Request Forgery
    • We need it for a user create
  • Server logs are your friends