![Page 1: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/1.jpg)
A Toolbox for
APIs &
Ben Ramsey php[tek] 21 May 2015
Integrations
![Page 2: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/2.jpg)
HI, I’M BEN.I’m a web craftsman, author, and speaker. I build a platform for professional photographers at ShootProof. I enjoy APIs, open source software, organizing user groups, good beer, and spending time with my family. Nashville, TN is my home.
virtPHP
✤ Books✤ Zend PHP Certification Study
Guide ✤ PHP 5 Unleashed
✤ Nashville PHP & Atlanta PHP✤ array_column()✤ rhumsaa/uuid library✤ virtPHP✤ PHP League OAuth 2.0 Client
![Page 3: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/3.jpg)
![Page 4: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/4.jpg)
A Toolbox for
APIs &Integrations
![Page 5: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/5.jpg)
application programming interface
![Page 6: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/6.jpg)
making a whole of parts
![Page 7: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/7.jpg)
APIs
![Page 8: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/8.jpg)
let’s start with some opinions
![Page 9: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/9.jpg)
RESTful
representational state transfer
![Page 10: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/10.jpg)
RESTful1. Client-server2. Stateless3. Cacheable4. Layered system5. Uniform interface6. Code on demand
![Page 11: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/11.jpg)
RESTful
hypermedia as theengine of application state
![Page 12: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/12.jpg)
RESTful
HATEOAS
![Page 13: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/13.jpg)
![Page 14: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/14.jpg)
![Page 15: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/15.jpg)
Authentication
OAuth 2.0
![Page 16: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/16.jpg)
Security
SSL all the things!
![Page 17: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/17.jpg)
URLs
In REST, URLs are opaque.
![Page 18: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/18.jpg)
URLs
They don’t matter.
![Page 19: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/19.jpg)
URLs
But, it’s nice to follow a pattern.
![Page 20: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/20.jpg)
URLs
Collection-Entity Pattern/collection/entity
![Page 21: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/21.jpg)
URLs
/contacts/1234
collection entity
![Page 22: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/22.jpg)
URLs: HTTP CRUD
GET /contacts POST /contacts
GET /contacts/1234 PUT /contacts/1234 DELETE /contacts/1234 PATCH /contacts/1234
Read collection of contactsCreate a new contact in this collection
Read contact 1234
Update contact 1234
Delete contact 1234
Partial update contact 1234
![Page 23: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/23.jpg)
Building
![Page 24: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/24.jpg)
Sinatra Pattern
Simple mapping of HTTP methods to URI routes.
![Page 25: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/25.jpg)
The Big (Micro) Three
1. Slim2. Lumen3. Silex
![Page 26: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/26.jpg)
$app->get('/hello/:name', function ($name) { echo "Hello, $name"; });
*Slim code
![Page 27: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/27.jpg)
GET /hello/world HTTP/1.1 Accept: */* Accept-Encoding: gzip, deflate Connection: keep-alive Host: example.org User-Agent: HTTPie/0.8.0
HTTP/1.1 200 OK Connection: close Content-type: text/html;charset=UTF-8 Host: example.org X-Powered-By: PHP/5.6.8
Hello, world
![Page 28: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/28.jpg)
What content type should I use for my API?
![Page 29: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/29.jpg)
HAL-JSON
a simple JSON format that specifies a way to create
hyperlinks between resources
![Page 30: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/30.jpg)
HAL-JSON
hypertext application language
![Page 32: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/32.jpg)
HTTP/1.1 200 OK Connection: close Content-Type: application/hal+json Host: example.org X-Powered-By: PHP/5.6.9
![Page 33: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/33.jpg)
{ "_embedded": { "contact": [ { "_links": { "self": { "href": "/contacts/56" } }, "address": "4545 Courthouse Rd", "city": "Westbury", "company_name": "Northwest Publishing", "county": "Nassau", "email": "[email protected]", "first_name": "Tonette", "last_name": "Wenner", "phone1": "516-968-6051", "phone2": "516-333-4861", "state": "NY", "web": "http://www.northwestpublishing.com", "zip": "11590" } ] }, "_links": { "next": { "href": "/contacts?page=57" }, "prev": { "href": "/contacts?page=55" }, "self": { "href": "/contacts?page=56" } } }
![Page 34: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/34.jpg)
{ "_embedded": { "contact": [ { "_links": { "self": { "href": "/contacts/56" } }, ... } ] }, "_links": { "next": { "href": "/contacts?page=57" }, "prev": { "href": "/contacts?page=55" }, "self": { "href": "/contacts?page=56" } } }
![Page 36: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/36.jpg)
$app->get('/contacts', function () use ($app) { $page = $app->request->get('page');
if ($page > 1) { $hal = new Hal('/contacts?page=' . $page); $hal->addLink('next', '/contacts?page=' . ($page + 1)); $hal->addLink('prev', '/contacts?page=' . ($page - 1)); } else { $page = 1; $hal = new Hal('/contacts'); $hal->addLink('next', '/contacts?page=2'); }
$contacts = getContactsPage($page);
foreach ($contacts as $id => $contact) { $resource = new Hal('/contacts/' . $id, $contact); $hal->addResource('contact', $resource); }
$app->response->headers->set('Content-Type', 'application/hal+json'); echo $hal->asJson(); });
*Slim code
![Page 37: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/37.jpg)
How do I deal with error messages?
![Page 38: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/38.jpg)
vnd.error
a simple way of expressing an error response in JSON
![Page 39: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/39.jpg)
HTTP/1.1 404 Not Found Connection: close Content-Type: application/vnd.error+json Host: example.org:8000 X-Powered-By: PHP/5.6.9
{ "_links": { "help": { "href": "http://docs.example.org/api/contacts", "title": "Contacts API Documentation" } }, "message": "Contact not found" }
![Page 41: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/41.jpg)
$app->get('/contacts/:id', function ($id) use ($app) { try {
$contact = getContactById($id); $hal = new Hal('/contacts/' . $id, $contact);
$app->response->headers->set('Content-Type', 'application/hal+json'); echo $hal->asJson();
} catch (ErrorException $e) {
$vndError = new VndError('Contact not found'); $vndError->addLink( 'help', 'http://docs.example.org/api/contacts', array('title' => 'Contacts API Documentation') );
$app->response->setStatus(404); $app->response->headers->set('Content Type', 'application/vnd.error+json'); echo $vndError->asJson();
} }); *Slim code
![Page 42: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/42.jpg)
How do I authenticate users to allow access to my API?
![Page 44: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/44.jpg)
Other options for building your APIs...
![Page 45: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/45.jpg)
Apigility
1. Opinionated API builder2. GUI interface to build APIs3. Zend Framework under the hood4. HAL and error responses5. Built-in OAuth 2.0 server
![Page 46: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/46.jpg)
![Page 48: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/48.jpg)
Apiary
1. Rapid prototyping of your API2. API Blueprint3. Server mocks4. Documentation-driven dev
![Page 49: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/49.jpg)
![Page 50: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/50.jpg)
![Page 52: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/52.jpg)
Debugging
![Page 54: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/54.jpg)
$ curl example.org/contacts\?page=43
{"_links":{"self":{"href":"\/contacts?page=43"},"next":{"href":"\/contacts?page=44"},"prev":{"href":"\/contacts?page=42"}},"_embedded":{"contact":[{"first_name":"Roxane","last_name":"Campain","company_name":"Rapid Trading Intl","address":"1048 Main St","city":"Fairbanks","county":"Fairbanks North Star","state":"AK","zip":"99708","phone1":"907-231-4722","phone2":"907-335-6568","email":"[email protected]","web":"http:\/\/www.rapidtradingintl.com","_links":{"self":{"href":"\/contacts\/43"}}}]}}
![Page 55: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/55.jpg)
HTTPie
1. User-friendly cURL replacement2. Lots of great features3. Sessions/cookie management4. httpie.org
![Page 56: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/56.jpg)
![Page 57: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/57.jpg)
Browser Dev Toolbars
1. All major browsers have them2. Inspect web requests as they fire in
the background3. See all headers, cookies, & data
![Page 58: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/58.jpg)
![Page 59: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/59.jpg)
Charles
1. HTTP proxy2. Essential tool for me3. Ability to record, modify, and play
requests4. www.charlesproxy.com
![Page 60: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/60.jpg)
![Page 61: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/61.jpg)
Paw
1. Elegant REST client2. Sorry, it’s Mac only3. Send request, inspect response4. PHP+Guzzle code generator5. luckymarmot.com/paw
![Page 62: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/62.jpg)
![Page 63: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/63.jpg)
Runscope Community Projects
1. hurl.it2. requestb.in3. httpbin.org
![Page 64: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/64.jpg)
Testing
![Page 65: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/65.jpg)
1. REST API testing framework2. Built on node.js and Jasmine3. Write tests in JavaScript4. Created by Vance Lucas5. frisbyjs.com
Frisby.js
![Page 66: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/66.jpg)
var frisby = require('frisby');
frisby.create('Contact Not Found') .get('http://example.org/contacts/501') .expectStatus(404) .expectHeaderContains('content-type', 'application/vnd.error+json') .expectJSON({ message: "Contact not found" }) .expectJSONTypes({ "_links": { help: { href: String, title: String } } }) .toss();
![Page 67: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/67.jpg)
frisby.create('Get Contact') .get('http://example.org/contacts/43') .expectStatus(200) .expectHeaderContains('content-type', 'application/hal+json') .expectJSON({ "_links": { self: { href: "/contacts/43" } } }) .expectJSONTypes({ address: String, city: String, company_name: String, county: String, email: String, first_name: String, last_name: String, phone1: String, phone2: String, state: String, web: String, zip: String }) .toss();
![Page 68: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/68.jpg)
$ ./node_modules/jasmine-node/bin/jasmine-node tests/spec ..
Finished in 0.077 seconds 2 tests, 20 assertions, 0 failures, 0 skipped
![Page 69: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/69.jpg)
![Page 70: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/70.jpg)
1. Open source project by Apiary2. Uses API Blueprint to test your API3. Ensures your docs are not outdated4. github.com/apiaryio/dredd
Dredd
![Page 71: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/71.jpg)
$ ./node_modules/dredd/bin/dredd
Configuration dredd.yml found, ignoring other arguments. Starting server with command: php -S 0.0.0.0:8000 index.php Waiting 3 seconds for server command to start... info: Beginning Dredd testing... pass: GET /contacts/42 duration: 46ms pass: GET /contacts duration: 113ms complete: 2 passing, 0 failing, 0 errors, 0 skipped, 2 total complete: Tests took 163ms
![Page 72: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/72.jpg)
1. Another OSS project by Apiary2. BDD testing for APIs3. Specify expectations and compare
to responses4. github.com/apiaryio/gavel
Gavel
![Page 73: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/73.jpg)
Consuming
![Page 74: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/74.jpg)
SDKs
1. Most APIs have SDKs, so search2. If not:• php.net/curl• Guzzle
![Page 75: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/75.jpg)
Right now, Guzzle is the best tool we have in PHP to consume APIs.
So, use it if there’s no SDK.
![Page 76: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/76.jpg)
Fin.
![Page 78: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/78.jpg)
THANK YOU. ANY QUESTIONS?If you want to talk more, feel free to contact me.
benramsey.com!
" @ramsey# github.com/ramsey$ [email protected]
joind.in/13746%A Toolbox for APIs and IntegrationsCopyright © 2015 Ben Ramsey
This work is licensed under Creative Commons Attribution-ShareAlike 4.0 International. For uses not covered under this license, please contact the author.
Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference presentation.
This presentation was created using Keynote. The text is set in Chunk Five and Helvetica Neue. The source code is set in Ubuntu Mono. The iconography is provided by Font Awesome.
Unless otherwise noted, all photographs are used by permission under a Creative Commons license. Please refer to the Photo Credits slide for more information.
![Page 79: A Toolbox for APIs & Integrations … · Ramsey, Ben. “A Toolbox for APIs and Integrations” php[tek]. Sheraton Chicago O’Hare Airport Hotel, Rosemont, IL. 21 May 2015. Conference](https://reader030.vdocument.in/reader030/viewer/2022012921/5f2b35c246ead1649078539d/html5/thumbnails/79.jpg)
PHOTO CREDITS1. “Toolbox” by Florian Richter, CC BY 2.0 2. “Day 90” by Wouter de Bruijn, CC BY-NC-SA 2.0 3. “Construction Cranes” by Daniel Foster, CC BY-NC-SA 2.0 4. “Repairs” by Ross Pollack, CC BY-NC-SA 2.0 5. “30 volt rms system voltage” by Thomas Lok, CC BY-ND 2.0 6. “Blueprint” by Will Scullin, CC BY 2.0 7. “Wrenched DOF” by LadyDragonflyCC, CC BY 2.0
1
2
3
4
5
6
7