#Building APIs
#Overview
- What is an API?
- Why build an API?
- Who is going to use it?
- What are they going to do?
- REST Architecture
- Stateless
- Resource Representations
- Client Server
- URIs
- Richardson Maturity Model (RESTful Routing)
- 0 - RPC
- 1 - Resources (have specific urls)
- 2 - Verbs and Response Codes
- 3 - HATEOAS - Self Describing
- Hypertest as the Engine of Application State????
- Links to available functionality in Responses
- Data Formats - Params, JSON, XML
- Error Handling
- Status Codes
- Error Messaging
- Authentication
- Open
- Client Tokens (Often ID + Secret)
- In Headers
- Consumption: Google GeoCode Example
- Providing: Playlist
- Challenge Prep
- Review
#What is an API?
- API is an Application Programming Interface
- Twitter Documentation
#Consumption: Google GeoCode Example
- geolocate
- Secure Your Tokens - DONT CHECK THEM IN!
dotenv
-.env
fileYAML.load()
- in*.yml
#Providing: Playlist
- RESTish - CRUD
- Richardson Maturity Model
- Richardson Maturity Model - extra
- HTTP Methods and Verbs
- JSON +?
- Only Provide what you need
- For External or Internal Use
- Authentication
- Talk about OAuth Later
- Key
- Exchange AppID and Secret for Token
- Header vs Param
- Often served over HTTPS
- Sinatra Moduluar Configuration - check it out
- petworld
- Postman Collection for Pet World
#Athena Example
module Athena
module ApiHelpers
def api_helpers_json_post_payload
request.body.rewind
payload = request.body.read
return JSON.parse(payload, :symbolize_names => true) unless payload.nil? || payload.empty?
{}
end
# ActiveModel::Serializer helper
def api_helpers_serialize(object, options = {})
klass = options[:serializer] || object.active_model_serializer
return object.to_json if klass.nil?
options[:scope] ||= nil
serializer = klass.new(object, options)
serializer.as_json.to_json
end
end
end
#Challenge Prep
- Challenge is to BUILD an API
- /build_an_api_challenge
- Postman Chrome Extension
- Petworld Example
#Review
- API is an Application Programming Interface
- For Web Applications:
- JSON reponses to params or JSON body requests
- Consumption either Server Side or Client Side
- Providing: PetWorld
- Challenge Prep
#Related Resources