Introduction to APIs - What, Why and How at CodeCore Bootcamp
-
Upload
codecore -
Category
Technology
-
view
637 -
download
0
description
Transcript of Introduction to APIs - What, Why and How at CodeCore Bootcamp
![Page 1: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/1.jpg)
Introduction to APIsCodeCore Community Week
April 25, 2014
Ganesh Swamiwww.silota.com
![Page 2: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/2.jpg)
Hi
• Programming professionally for 10+ years
• x86 assembly, STL, boost, python-boost, python
![Page 3: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/3.jpg)
SILOTA• Search As A Service
• full stack: crawling, indexing, retrieving, tag deployment
• First class developer experience (DX)
• documentation
• testing
• sandbox
• 800+ search engines in production!
![Page 4: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/4.jpg)
APIs: What & Why
![Page 5: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/5.jpg)
What is an API?Application Programming Interface
!An API is the interface implemented by an
application which allows other applications to communicate with it.
![Page 6: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/6.jpg)
What is an API?
communicate
![Page 7: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/7.jpg)
Why build an API?
• explosion of devices connected to the internet
• can be a company’s greatest asset
• bizdev 2.0: internal developers, consultants, partners, customers
![Page 8: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/8.jpg)
Sample APIs• aws
• dropbox
• github
• stripe
• salesforce
• twillio
• …
![Page 9: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/9.jpg)
Source: Mary Meeker’s Internet Trends 2013
![Page 10: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/10.jpg)
APIs: How
![Page 11: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/11.jpg)
What is REST?• REpresentational State Transfer
• logical resources manipulated with HTTP verbs
• modern best practice
• wide adoption
• contrast with SOAP
![Page 12: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/12.jpg)
HTTP Clients
Request Response
GET /simtec/httpgallery/introduction/ HTTP/1.1 Accept:*/* Accept-‐Language: en-‐gb Accept-‐Encoding: gzip, deflate User-‐Agent: Mozilla/4.0 (compatible; MSIE 6.0) Host: www.httpwatch.com Connection: Keep-‐Alive !!!!!
HTTP/1.1 200 OK Server: Microsoft-‐IIS/5.1 Date: Mon, 04 Oct 2004 12:04:43 GMT X-‐Powered-‐By: ASP.NET X-‐AspNet-‐Version: 1.1.4322 Cache-‐Control: no-‐cache Pragma: no-‐cache Expires: -‐1 Content-‐Type: text/html; charset=utf-‐8 Content-‐Length: 8307 !<html> <head> ...
![Page 13: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/13.jpg)
HTTP Verbs
• GET, POST, PUT, PATCH, DELETE
![Page 14: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/14.jpg)
Status Codes
2xx OK, created, all good, carry on
4xx User error: bad API key, malformed data, item not found, etc.
5xx Server error
![Page 15: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/15.jpg)
Embrace HTTPGET /document Retrieve all documents
GET /document/19 Retrieve a specific document #19
POST /document Create a new document
PUT /document/19 Update an existing document #19
DELETE /document/19 Delete an existing document #19
![Page 16: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/16.jpg)
![Page 17: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/17.jpg)
Postman: Chrome Extension
![Page 18: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/18.jpg)
Bipartite graph/documents /documents/:id …
GET
POST error
PUT error
PATCH error
DELETE
![Page 19: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/19.jpg)
Best practicessecurity
base URLs
serialization
timestamps
versioning
caching
gzip
logging
![Page 20: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/20.jpg)
Best practicessecurity https all the way
base URLs api.companyname.com
serialization json
timestamps ISO 8601 & UTC
versioning /v1/
caching ETag & Last-Modified
gzip always & pretty print responses
logging if possible
![Page 21: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/21.jpg)
Recap
• https + gzip + json
• use bipartite graph of nouns and verbs
• great documentation
• no surprises
![Page 22: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/22.jpg)
Integration Challenges
![Page 24: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/24.jpg)
Handling Timeouts
![Page 25: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/25.jpg)
The Pitch
BENEFITSCOSTS
What We Give (investment)
What We Get (return)
![Page 26: Introduction to APIs - What, Why and How at CodeCore Bootcamp](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549246eb4c9054c498ba7bc/html5/thumbnails/26.jpg)
References• How to Design a Good API and Why it Matters:
• http://lcsd05.cs.tamu.edu/slides/keynote.pdf
• Best Practices for Designing a Pragmatic RESTful API
• http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api
• REST worst practices:
• http://jacobian.org/writing/rest-worst-practices/
• Building RESTful APIs: http://www.slideshare.net/silota/building-restful-apis