Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
What is an API
Search
Jesse Wolgamott
February 24, 2017
Technology
0
170
What is an API
BEGINNER level on what is a (server-side JSON) API
Jesse Wolgamott
February 24, 2017
Tweet
Share
More Decks by Jesse Wolgamott
See All by Jesse Wolgamott
React vs React-Native
jwo
0
96
DIY Rails Authentication
jwo
0
180
ActionCable - For Not Another Chat App
jwo
3
1.4k
SlackBot.rb - Create You a Slack Bot
jwo
1
1.2k
react-rails: an isomorphic match made in heaven
jwo
0
1.2k
Docker - next big thing
jwo
0
830
Ruby 2.1 Overview
jwo
0
830
Rails 4: Appetizers
jwo
1
840
The Long Ball: Upgrading Rails from 1.2 -> 4.0
jwo
2
180
Other Decks in Technology
See All in Technology
急成長中のWINTICKETにおける品質と開発スピードと向き合ったQA戦略と今後の展望 / winticket-autify
cyberagentdevelopers
PRO
1
120
入門『状態』#kaigionrails / "state" for beginners with Rails
shinkufencer
2
810
生成AI×マルチテナントSaaSな新規事業を立ち上げる上でテックリードとして気を使った点の紹介
lunastera
0
530
都市伝説バスターズ「WebアプリのボトルネックはDBだから言語の性能は関係ない」 - Kaigi on Rails 2024
osyoyu
13
4.8k
Emacs x Nostr
hakkadaikon
1
120
2024-10-30-reInventStandby_StudyGroup_Intro
shinichirokawano
1
230
AIを使って小説を書こう!【2024/10/25講演資料】
kamomeashizawa
0
160
サイバーエージェントにおける生成AIのリスキリング施策の取り組み / cyber-ai-reskilling
cyberagentdevelopers
PRO
1
130
GitHub Universe: Evaluating RAG apps in GitHub Actions
pamelafox
0
130
Kubernetes Summit 2024 Keynote:104 在 GitOps 大規模實踐中的甜蜜與苦澀
yaosiang
0
270
新R25、乃木坂46 Mobileなどのファンビジネスを支えるマルチテナンシーなプラットフォームの全体像 / cam-multi-cloud
cyberagentdevelopers
PRO
1
110
最速最小からはじめるデータプロダクト / Data Product MVP
amaotone
1
370
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
360
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Making the Leap to Tech Lead
cromwellryan
132
8.9k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Rails Girls Zürich Keynote
gr2m
93
13k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
The Cost Of JavaScript in 2023
addyosmani
45
6.2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.8k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
228
52k
Testing 201, or: Great Expectations
jmmastey
38
7k
Transcript
APIs An exploration into the past, present, and future parts
of web microservice and their place in current modern tech culture.
APIs What is an API?
Why APIs?
Mobile Devices
JS Frameworks
Email? SMS? Twitter?
Me
Jesse Wolgamott • Former Instructor, Back-End Engineer at TIY Houston
• Currently: Director, Back-end Engineering, The Iron Yard • Developer since 1997 • First JSON API: 2002
History
History, Quickly • API: “Application Programming Interface” • Standard input/output
for a library to be used and re-used • Computers have APIs (BIOS, Hard Drives, Operating Systems)
History, Quickly • Software worked over the “network” before the
internet • They would connect via “APIs” to a remote server. • Known as “Client/Server”
History, Quickly • The “internet” resembled this • People said,
let’s expose “data” over the internet via an “API” • It stuck
API Requests • There’s no difference between your browser requesting
facebook.com and a computer program making an “API” call • facebook.com might return HTML to your browser and JSON to the program
Headers • Both requests and responses contain “headers” • Headers
are sent/received with all requests/responses • They help browsers and computers do their thing
The Request
It’s called a Request no matter if you are requesting
data or sending data
Requests • URL • Method • Content-Type • Accepts
URL http://www.domain.com/users/56 Protocol Domain Path Resource ID
URL • Each “Entity” has one specific URL. • The
best URLs are “guessable”
Method • Each Request has an HTTP-Method • GET ->
request data • POST -> here’s new (or updated) data • DELETE -> delete data at this URL • PATCH -> here’s what to update
Content Type • Specified via a “HEADER” • When sending
data (POST/PATCH), tells server if you’re sending JSON or XML or JWOML
Accept • Specified via a “HEADER” • Tells server what
type of data you want to receive back, such as JSON, XML, or JWOML
The Response
Status Code • Specified via a “HEADER” • Tells the
client all sorts of things
OK Status Codes • 200: OK • 201: Created •
301: Over there (always) • 302: Over there (temporarily)
NotGreat Status Codes • 400: Generic Bad, but your bad
• 401: You are not authenticated • 404: Not Found • 422: Errors found in your data
RealBad Status Codes • 500: Big huge problem, it’s my
fault • 503: Service is down
General Status Codes • 200: OK • 300: Over There
• 400: [BLEEP] You • 500: [BLEEP] Me
Shape of Data • Each server will return different shapes
of data • This is dependent of whatever developer happened to code that one day they were employed there
Shape of Data • You have to exactly know the
shape of data to get anything of value out of the API • You won’t know the shape of data until making calls and manually looking at data
Exchange Rates response.rates.AUD
GitHub Repos [0].owner.login
JSON API Sample data[0].attributes.title
Shape of Data • Sometimes the base object is a
key, sometimes it’s an array • When you get this wrong, it brakes
Tools
Without JSON-View Formats JSON in Browsers
With JSON-View Formats JSON in Browsers
Postman Set headers, post data, receive data
Essential Tools • You have to exactly know the shape
of data to get anything of value out of the API • You won’t know the shape of data until making calls and manually looking at data • Sometimes you get documentation • Sometimes documentation is out of date
Authentication
Authentication Who You are
Authentication What App Are You Using?
User Authentication • User Authorization: Trade username and password for
a token • All requests then contain token. • Without request, 401 • Token can be in Header or a URL parameter.
App Authentication • Each App is given a token to
use for the App itself • ApiToken is usually a Header, but can also be a URL parameter
Authorization \What You Can See
Oauth
Way for Internet users to authorize websites or applications to
access their information on other websites but without giving them the passwords.
Way for Internet users to authorize websites or applications to
access their information on other websites but without giving them the passwords.
Two Types • Password Grant - used for me to
trade my username/password on a site for an auth token • Sign in with Facebook / Google / Spotify / GitHub, etc
It’s Just That Easy™
Oauth Difficulty • Difficult to get the “Connect” oauth right
• It is also the only responsible way to get a user’s information to your site from a second site
Standards (attempts)
JSON-API • Created by the EmberJS team, JSON-API attempts to
standardize the shape of the JSON responses • Results outside of Ember: not-great
GraphQL • “Hot Future” of JSON-APIs. • Query for what
you want, instead of returning ALL data.
PRO Tips
CORS • Helps protect information • Feels like it gets
in your way • If API protects against CORS, you use a server-side proxy to get around
JSON-P • Can cross CORS boundary • You specify a
callback to be called by server • (I’d rather just have a proxy)
More Logging • console.log() the response you actually get •
Don’t assume documentation is up to date, accurate, or nice
Great APIs Have
Great Expectations • Versioning • API Keys • Runnable Documentation
• Sample Libraries • Does just about what you’d expect
Publishing APIs
Microservices • JavaScript: Express, KOA, HAPI • Ruby: Sinatra •
C#: Nancy • Swift: Taylor
Larger Frameworks • Node: Adonis • Ruby: Rails • C#:
ASP.NET MVC • Swift: Vapor / Perfect