@zgordon About Zac Gordon Education Middle school High school College Workshops Conferences Business WordPress Treehouse Calendrics Stripe Social stuff
@zgordon API: Application Programming Interface About APIs Lets sites and applications do one-way and two-way communication. 3 Types: Internal, Public Facing, External
@zgordon Internal APIs - Used within an application Internal APIs $args = array( 'post_type' => 'work', 'author_name' => 'zgordon', 'orderby' => 'title' ); $the_query = new WP_Query( $args ); SELECT * FROM wp_posts WHERE post_type = work AND author_name = zgordon ORDER BY title WordPress Example - Get Developer’s Work
@zgordon Public Facing - An internal API that you open to external applications Public Facing APIs - REST architecture - API versioning - Authentication
@zgordon REST applies data endpoints using the conventional HTTP url architecture REST Architecture not exactly CRUD GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH GET /users/{username}
@zgordon Versioning addresses updating your API while maintaining backwards compatibility API Versioning api.app.net VS api.app.net/v1 Initial launch api.app.net/v2 And then
@zgordon Passwords API Authentication Tokens Pass either username and be prompted for password, or pass both together Unique identifiers for an app, user, level of access or single transaction
@zgordon GitHub Example - OAuth External APIs GET https://github.com/login/oauth/authorize POST https://github.com/login/oauth/access_token access_token=e72e16c7e42f292c6912e7710c838347ae17.. GET https://api.github.com/user?access_token=...
@zgordon Data Replay Data Replay lets you use cached data for testing API requests and responses. VCR - Caches the initial return class VCRTest < Test::Unit::TestCase def test_example_dot_com VCR.use_cassette('response') do response = Net::HTTP.get_response(URI('http://api.app.net/v1/users')) assert_match /Example domains/, response.body end end end
@zgordon Faking It “Faking It” involves creating your own requests to use instead of live requests FakeWeb - Create your own response FakeWeb.register_uri(:get, "http://api.app.net/v1/users", :body => "Everyone is here!") Net::HTTP.get(URI.parse("http://api.app.net/v1/users")) => "Everyone is here!"
@zgordon Debugging Charles - Much more powerful API debugging tool - SSL Proxying - Bandwidth Throttling - AJAX debugging - AMF [Flash/Flex Remoting] - Repeat requests to test back-end changes - Edit requests to test different inputs - Breakpoints to intercept and edit requests/responses - Validate responses using the W3C validator
@zgordon Rate Limiting Rate Limiting controls the frequency a client can interact with the API. Done at the server level ngx_http_limit_req_module - Limits number of requests from IP in a set amount of time HAProxy - Can limit based on amount of data transferred