Skip to content

Instantly share code, notes, and snippets.

@lisaSwanson
Forked from stujo/building-apis.md
Last active August 31, 2015 16:29
Show Gist options
  • Save lisaSwanson/b3353fc1fcd2933c71be to your computer and use it in GitHub Desktop.
Save lisaSwanson/b3353fc1fcd2933c71be to your computer and use it in GitHub Desktop.

#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?

#Consumption: Google GeoCode Example

  • geolocate
  • Secure Your Tokens - DONT CHECK THEM IN!
    • dotenv - .env file
    • YAML.load() - in *.yml

#Providing: Playlist

#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

#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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment