SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
Crafting WEB API Design that
Developers Love. Deep dive
Roman Bugaev, Senior developer at Adform
About us • 400+ high performance servers
• High availability load balancing and failover
• 200 000 requests per second
• Peta Bytes of data on 50+ servers
• Up to 20 releases per day
• Integrations
•
•
•
•

Facebook, Google, Adobe
Large e-shops and CMS platform
TV ads recognition
Adform Marketplace
Why?
~70% API – REST

"there is no 'official' standard for RESTful web

Interviews
Pragmatic REST
• REST is an architectural style and not a strict
standard, it allows for a lot of flexibly
• The primary design principle when crafting your API
should be to maximize developer productivity and
success.
• Pragmatic REST is a design problem
• Keep simple things simple
Keep base URL simple & intuitive
• Nouns are good; verbs are bad
• 2 base URLs per resource
• /users
/users/1234

• Keep verbs out of your base URLs
• Use HTTP verbs to operate on the collections and
elements.
• POST create
GET read
PUT update DELETE
delete
How to pick the nouns for URLs.
• Plural rather than singular nouns
• Foursquare
• Dropbox
• Facebook

/checkins
/files
/me/friends

• Concrete rather than abstract names
• /items vs. /blogs, /news
Simplify associations
• GET /folders/5678/files
• Get all files belonging to a specific folder

• POST /folders/5678/files
• Create new file for that folder
Sweep complexity behind the ‘?’
• Attributes GET
/cars?color=red&state=new&location=minsk
• Paging GET /cars?limit=25&offset=50
• Global Search GET /search?q=lamb

• Scoped Search GET /owners/5678/cars?q=lamb
Handling errors
• Developers learn to write code through errors
• Developers depend on well-designed errors at the
critical times
Handling errors - Facebook
HTTP Status Code 200
{
error:
{
message: “Malformed access token <token>”,
type: “OAuthException”,
code: “190”
}
}
Handling errors - Twilio
HTTP Status Code: 401
{
status: "401",
message: "Authenticate",
code: 20003,
info: "http://www.twilio.com/docs/errors/20003"
}
A couple of best practices
• Use HTTP status codes
• Make messages returned in the payload as verbose as
possible
•
•
•
•

Code
Developer message
User message
More Info

I ❤ BEST
PRACTICES

Start by using the following 3 codes:
• 200 – OK (success)
• 400 - Bad Request (client error)
• 500 - Internal Server Error (server error)
Tips for versioning
• salesforce.com
/services/data/v20.0/sobjects/Account
• Facebook ?v=1.0

• The version is mandatory.
• Accept header for entity versioning
• Specify the version with a 'v' prefix.
• Use a simple ordinal number.
• Create an alias for current version
Actions
• Use verbs not nouns:
• /convert?from=EUR&to=CNY&amount=100

• Make it clear in your API documentation that these
“non-resource” scenarios are different.
Probe Web Resources Efficiently
with OPTIONS in REST
< HTTP/1.1 200 OK
< Allow: GET, HEAD, POST, OPTIONS, TRACE
< Content-Type: text/html; charset=UTF-8
< Date: Wed, 13 December 2013 10:24:43 GMT
< Content-Length: 0
Probe Web Resources Efficiently
with HEAD in REST
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Content-Type: text/html; charset=UTF-8
< Date: Wed, 08 May 2013 10:12:29 GMT
< ETag: "780602-4f6-4db31b2978ec0"
< Last-Modified: Thu, 25 Apr 2013 16:13:23 GMT
< Content-Length: 1270
Scale
• Think about scale sooner that later
• Rate limits
• Extra servers
• Partitioning
• Caching
•
•
•
•

Between application and database
In the application itself
Using an API proxy
CDN for large static content
Supporting multiple formats
• To get the JSON format from a collection or specific
element:
• dogs.json
• /dogs/1234.json
Accept header for entity versioning also applicable
Default format: JSON

Follow JavaScript conventions
Chatty APIs
Imagine how developers will use your API
• You can design a RESTful API and still mitigate the
chattiness.
Be complete and RESTful and provide shortcuts
Take advantage of the partial response syntax
• /owners/5678?fields=name, dogs.name
Some useful tools
Apiary.io
Apigee
Runscope, hurl.it, apichangelog
Mashape
Security
• Use something established
• API keys for non-sensitive data only
• Username/password auth for site based
APIs
• OAuth for server-to-server APIs
• SSL for EVERYTHING sensitive
OAuth
1. An OAuth token gives one app access to one API
on behalf of one user.
2. App developers do not want responsibility of
holding a user’s secret information (password).
3. there are three entities (legs) – user/server/client
Why is OAuth important?
• What if client is hacked and someone steals all the
passwords?
• OAuth allows the API provider to revoke tokens for an
individual user and for an entire app

• On the other hand, if user decides to change his
password, the token will be the same.
• Developers can use an OAuth library in their
language
Types of OAuth 2.0
• BEARER TOKEN
• SSL and big numbers

• MAC TOKEN
• Uses signature instead of SSL

• SAML
• if you and your potential API developers don’t
understand SAML or know what it is, that’s a signal to
stay away
Thank you! Questions?

rbugaev@gmail.com
bugaev_roman
http://twitter.com/rbugaev
http://facebook.com/rbugaev

Weitere ähnliche Inhalte

Was ist angesagt?

Building SharePoint 2013 Apps - Architecture, Authentication & Connectivity API
Building SharePoint 2013 Apps - Architecture, Authentication & Connectivity APIBuilding SharePoint 2013 Apps - Architecture, Authentication & Connectivity API
Building SharePoint 2013 Apps - Architecture, Authentication & Connectivity API
SharePointRadi
 
Practical management of development & QA environments for SharePoint 2013
Practical management of development & QA environments for SharePoint 2013Practical management of development & QA environments for SharePoint 2013
Practical management of development & QA environments for SharePoint 2013
SharePointRadi
 
Visio Services in SharePoint 2010
Visio Services in SharePoint 2010Visio Services in SharePoint 2010
Visio Services in SharePoint 2010
Alexander Meijers
 
Access share point-2013-data-with-provider-hosted-apps
Access share point-2013-data-with-provider-hosted-appsAccess share point-2013-data-with-provider-hosted-apps
Access share point-2013-data-with-provider-hosted-apps
Alexander Meijers
 

Was ist angesagt? (20)

Developing Apps for SharePoint Store
Developing Apps for SharePoint StoreDeveloping Apps for SharePoint Store
Developing Apps for SharePoint Store
 
Reasons to Upgrade to DNN Evoq Content Version 7
Reasons to Upgrade to DNN Evoq Content Version 7Reasons to Upgrade to DNN Evoq Content Version 7
Reasons to Upgrade to DNN Evoq Content Version 7
 
Feature List
Feature ListFeature List
Feature List
 
Product Update Elvis - Salesforce integration, Multi-tiered storage, File nam...
Product Update Elvis - Salesforce integration, Multi-tiered storage, File nam...Product Update Elvis - Salesforce integration, Multi-tiered storage, File nam...
Product Update Elvis - Salesforce integration, Multi-tiered storage, File nam...
 
Building SharePoint 2013 Apps - Architecture, Authentication & Connectivity API
Building SharePoint 2013 Apps - Architecture, Authentication & Connectivity APIBuilding SharePoint 2013 Apps - Architecture, Authentication & Connectivity API
Building SharePoint 2013 Apps - Architecture, Authentication & Connectivity API
 
Apps for SharePoint
Apps for SharePointApps for SharePoint
Apps for SharePoint
 
Practical management of development & QA environments for SharePoint 2013
Practical management of development & QA environments for SharePoint 2013Practical management of development & QA environments for SharePoint 2013
Practical management of development & QA environments for SharePoint 2013
 
SharePoint 2013 Search and Creating Dynamic Content Management Solutions
SharePoint 2013 Search and Creating Dynamic Content Management SolutionsSharePoint 2013 Search and Creating Dynamic Content Management Solutions
SharePoint 2013 Search and Creating Dynamic Content Management Solutions
 
Developing SharePoint 2013 apps with Visual Studio 2012 - Microsoft TechDays ...
Developing SharePoint 2013 apps with Visual Studio 2012 - Microsoft TechDays ...Developing SharePoint 2013 apps with Visual Studio 2012 - Microsoft TechDays ...
Developing SharePoint 2013 apps with Visual Studio 2012 - Microsoft TechDays ...
 
Hosting a website on IIS Server
Hosting a website on IIS ServerHosting a website on IIS Server
Hosting a website on IIS Server
 
Visio Services in SharePoint 2010
Visio Services in SharePoint 2010Visio Services in SharePoint 2010
Visio Services in SharePoint 2010
 
Access share point-2013-data-with-provider-hosted-apps
Access share point-2013-data-with-provider-hosted-appsAccess share point-2013-data-with-provider-hosted-apps
Access share point-2013-data-with-provider-hosted-apps
 
Building Quality into the AEM Publication Workflow with Active Standards by D...
Building Quality into the AEM Publication Workflow with Active Standards by D...Building Quality into the AEM Publication Workflow with Active Standards by D...
Building Quality into the AEM Publication Workflow with Active Standards by D...
 
Restful api design
Restful api designRestful api design
Restful api design
 
Building the Eventbrite API Ecosystem
Building the Eventbrite API EcosystemBuilding the Eventbrite API Ecosystem
Building the Eventbrite API Ecosystem
 
Developer’s Independence Day: Introducing the SharePoint App Model
Developer’s Independence Day:Introducing the SharePoint App ModelDeveloper’s Independence Day:Introducing the SharePoint App Model
Developer’s Independence Day: Introducing the SharePoint App Model
 
IBM Digital Experience Theme Customization
IBM Digital Experience Theme CustomizationIBM Digital Experience Theme Customization
IBM Digital Experience Theme Customization
 
Easy Web Serivce on iOS with Pico
Easy Web Serivce on iOS with PicoEasy Web Serivce on iOS with Pico
Easy Web Serivce on iOS with Pico
 
IBM Social Business Toolkit
IBM Social Business ToolkitIBM Social Business Toolkit
IBM Social Business Toolkit
 
ECS19 - Michael Greth - Best Practice with Company Video on Microsoft Stream
ECS19 - Michael Greth - Best Practice with Company Video on Microsoft StreamECS19 - Michael Greth - Best Practice with Company Video on Microsoft Stream
ECS19 - Michael Greth - Best Practice with Company Video on Microsoft Stream
 

Ähnlich wie Создание API, которое полюбят разработчики. Глубокое погружение

Designing your API Server for mobile apps
Designing your API Server for mobile appsDesigning your API Server for mobile apps
Designing your API Server for mobile apps
Mugunth Kumar
 
How to Build, Manage, and Promote APIs
How to Build, Manage, and Promote APIsHow to Build, Manage, and Promote APIs
How to Build, Manage, and Promote APIs
WSO2
 

Ähnlich wie Создание API, которое полюбят разработчики. Глубокое погружение (20)

Building a Great Web API - Evan Cooke - QCON 2011
Building a Great Web API - Evan Cooke - QCON 2011Building a Great Web API - Evan Cooke - QCON 2011
Building a Great Web API - Evan Cooke - QCON 2011
 
API Economy, Realizing the Business Value of APIs
API Economy, Realizing the Business Value of APIsAPI Economy, Realizing the Business Value of APIs
API Economy, Realizing the Business Value of APIs
 
Building A Great API - Evan Cooke, Cloudstock, December 2010
Building A Great API - Evan Cooke, Cloudstock, December 2010Building A Great API - Evan Cooke, Cloudstock, December 2010
Building A Great API - Evan Cooke, Cloudstock, December 2010
 
Building RESTful APIs
Building RESTful APIsBuilding RESTful APIs
Building RESTful APIs
 
Api fundamentals
Api fundamentalsApi fundamentals
Api fundamentals
 
BeEF_EUSecWest-2012_Michele-Orru
BeEF_EUSecWest-2012_Michele-OrruBeEF_EUSecWest-2012_Michele-Orru
BeEF_EUSecWest-2012_Michele-Orru
 
Coding 100-session-slides
Coding 100-session-slidesCoding 100-session-slides
Coding 100-session-slides
 
Api FUNdamentals #MHA2017
Api FUNdamentals #MHA2017Api FUNdamentals #MHA2017
Api FUNdamentals #MHA2017
 
Developing Apps with Azure AD
Developing Apps with Azure ADDeveloping Apps with Azure AD
Developing Apps with Azure AD
 
Building a REST API for Longevity
Building a REST API for LongevityBuilding a REST API for Longevity
Building a REST API for Longevity
 
CNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application TechnologiesCNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application Technologies
 
Designing your API Server for mobile apps
Designing your API Server for mobile appsDesigning your API Server for mobile apps
Designing your API Server for mobile apps
 
Modernize Service-Oriented Architecture with APIs
Modernize Service-Oriented Architecture with APIsModernize Service-Oriented Architecture with APIs
Modernize Service-Oriented Architecture with APIs
 
Global Azure 2022 - Architecting Modern Serverless APIs with Azure Functions ...
Global Azure 2022 - Architecting Modern Serverless APIs with Azure Functions ...Global Azure 2022 - Architecting Modern Serverless APIs with Azure Functions ...
Global Azure 2022 - Architecting Modern Serverless APIs with Azure Functions ...
 
How to Build, Manage, and Promote APIs
How to Build, Manage, and Promote APIsHow to Build, Manage, and Promote APIs
How to Build, Manage, and Promote APIs
 
CNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application TechnologiesCNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application Technologies
 
Secure your app with keycloak
Secure your app with keycloakSecure your app with keycloak
Secure your app with keycloak
 
Lessons learned on the Azure API Stewardship Journey.pptx
Lessons learned on the Azure API Stewardship Journey.pptxLessons learned on the Azure API Stewardship Journey.pptx
Lessons learned on the Azure API Stewardship Journey.pptx
 
Rest ful tools for lazy experts
Rest ful tools for lazy expertsRest ful tools for lazy experts
Rest ful tools for lazy experts
 
RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016
 

Mehr von SQALab

Mehr von SQALab (20)

Готовим стажировку
Готовим стажировкуГотовим стажировку
Готовим стажировку
 
Куда приводят мечты? или Искусство развития тестировщика
Куда приводят мечты? или Искусство развития тестировщикаКуда приводят мечты? или Искусство развития тестировщика
Куда приводят мечты? или Искусство развития тестировщика
 
Оптимизация Selenium тестов и ускорение их поддержки
Оптимизация Selenium тестов и ускорение их поддержкиОптимизация Selenium тестов и ускорение их поддержки
Оптимизация Selenium тестов и ускорение их поддержки
 
Автоматизация 0.0: 0 - бюджет, 0 - опыт программирования
Автоматизация 0.0: 0 - бюджет, 0 - опыт программированияАвтоматизация 0.0: 0 - бюджет, 0 - опыт программирования
Автоматизация 0.0: 0 - бюджет, 0 - опыт программирования
 
Нагрузочное тестирование нестандартных протоколов с использованием Citrix и J...
Нагрузочное тестирование нестандартных протоколов с использованием Citrix и J...Нагрузочное тестирование нестандартных протоколов с использованием Citrix и J...
Нагрузочное тестирование нестандартных протоколов с использованием Citrix и J...
 
Continuous performance testing
Continuous performance testingContinuous performance testing
Continuous performance testing
 
Конфиги вместо костылей. Pytestconfig и зачем он нужен
Конфиги вместо костылей. Pytestconfig и зачем он нуженКонфиги вместо костылей. Pytestconfig и зачем он нужен
Конфиги вместо костылей. Pytestconfig и зачем он нужен
 
Команда чемпионов в ИТ стихии
Команда чемпионов в ИТ стихииКоманда чемпионов в ИТ стихии
Команда чемпионов в ИТ стихии
 
API. Серебряная пуля в магазине советов
API. Серебряная пуля в магазине советовAPI. Серебряная пуля в магазине советов
API. Серебряная пуля в магазине советов
 
Добиваемся эффективности каждого из 9000+ UI-тестов
Добиваемся эффективности каждого из 9000+ UI-тестовДобиваемся эффективности каждого из 9000+ UI-тестов
Добиваемся эффективности каждого из 9000+ UI-тестов
 
Делаем автоматизацию проектных KPIs
Делаем автоматизацию проектных KPIsДелаем автоматизацию проектных KPIs
Делаем автоматизацию проектных KPIs
 
Вредные привычки в тест-менеджменте
Вредные привычки в тест-менеджментеВредные привычки в тест-менеджменте
Вредные привычки в тест-менеджменте
 
Мощь переполняет с JDI 2.0 - новая эра UI автоматизации
Мощь переполняет с JDI 2.0 - новая эра UI автоматизацииМощь переполняет с JDI 2.0 - новая эра UI автоматизации
Мощь переполняет с JDI 2.0 - новая эра UI автоматизации
 
Как hh.ru дошли до 500 релизов в квартал без потери в качестве
Как hh.ru дошли до 500 релизов в квартал без потери в качествеКак hh.ru дошли до 500 релизов в квартал без потери в качестве
Как hh.ru дошли до 500 релизов в квартал без потери в качестве
 
Стили лидерства и тестирование
Стили лидерства и тестированиеСтили лидерства и тестирование
Стили лидерства и тестирование
 
"Давайте не будем про качество"
"Давайте не будем про качество""Давайте не будем про качество"
"Давайте не будем про качество"
 
Apache.JMeter для .NET-проектов
Apache.JMeter для .NET-проектовApache.JMeter для .NET-проектов
Apache.JMeter для .NET-проектов
 
Тестирование геолокационных систем
Тестирование геолокационных системТестирование геолокационных систем
Тестирование геолокационных систем
 
Лидер или босс? Вот в чем вопрос
Лидер или босс? Вот в чем вопросЛидер или босс? Вот в чем вопрос
Лидер или босс? Вот в чем вопрос
 
От Зефира в коробке к Structure Zephyr или как тест-менеджеру перекроить внут...
От Зефира в коробке к Structure Zephyr или как тест-менеджеру перекроить внут...От Зефира в коробке к Structure Zephyr или как тест-менеджеру перекроить внут...
От Зефира в коробке к Structure Zephyr или как тест-менеджеру перекроить внут...
 

Kürzlich hochgeladen

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Kürzlich hochgeladen (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 

Создание API, которое полюбят разработчики. Глубокое погружение

  • 1. Crafting WEB API Design that Developers Love. Deep dive Roman Bugaev, Senior developer at Adform
  • 2. About us • 400+ high performance servers • High availability load balancing and failover • 200 000 requests per second • Peta Bytes of data on 50+ servers • Up to 20 releases per day • Integrations • • • • Facebook, Google, Adobe Large e-shops and CMS platform TV ads recognition Adform Marketplace
  • 3. Why? ~70% API – REST "there is no 'official' standard for RESTful web Interviews
  • 4. Pragmatic REST • REST is an architectural style and not a strict standard, it allows for a lot of flexibly • The primary design principle when crafting your API should be to maximize developer productivity and success. • Pragmatic REST is a design problem • Keep simple things simple
  • 5. Keep base URL simple & intuitive • Nouns are good; verbs are bad • 2 base URLs per resource • /users /users/1234 • Keep verbs out of your base URLs • Use HTTP verbs to operate on the collections and elements. • POST create GET read PUT update DELETE delete
  • 6. How to pick the nouns for URLs. • Plural rather than singular nouns • Foursquare • Dropbox • Facebook /checkins /files /me/friends • Concrete rather than abstract names • /items vs. /blogs, /news
  • 7. Simplify associations • GET /folders/5678/files • Get all files belonging to a specific folder • POST /folders/5678/files • Create new file for that folder
  • 8. Sweep complexity behind the ‘?’ • Attributes GET /cars?color=red&state=new&location=minsk • Paging GET /cars?limit=25&offset=50 • Global Search GET /search?q=lamb • Scoped Search GET /owners/5678/cars?q=lamb
  • 9. Handling errors • Developers learn to write code through errors • Developers depend on well-designed errors at the critical times
  • 10. Handling errors - Facebook HTTP Status Code 200 { error: { message: “Malformed access token <token>”, type: “OAuthException”, code: “190” } }
  • 11. Handling errors - Twilio HTTP Status Code: 401 { status: "401", message: "Authenticate", code: 20003, info: "http://www.twilio.com/docs/errors/20003" }
  • 12. A couple of best practices • Use HTTP status codes • Make messages returned in the payload as verbose as possible • • • • Code Developer message User message More Info I ❤ BEST PRACTICES Start by using the following 3 codes: • 200 – OK (success) • 400 - Bad Request (client error) • 500 - Internal Server Error (server error)
  • 13. Tips for versioning • salesforce.com /services/data/v20.0/sobjects/Account • Facebook ?v=1.0 • The version is mandatory. • Accept header for entity versioning • Specify the version with a 'v' prefix. • Use a simple ordinal number. • Create an alias for current version
  • 14. Actions • Use verbs not nouns: • /convert?from=EUR&to=CNY&amount=100 • Make it clear in your API documentation that these “non-resource” scenarios are different.
  • 15. Probe Web Resources Efficiently with OPTIONS in REST < HTTP/1.1 200 OK < Allow: GET, HEAD, POST, OPTIONS, TRACE < Content-Type: text/html; charset=UTF-8 < Date: Wed, 13 December 2013 10:24:43 GMT < Content-Length: 0
  • 16. Probe Web Resources Efficiently with HEAD in REST < HTTP/1.1 200 OK < Accept-Ranges: bytes < Content-Type: text/html; charset=UTF-8 < Date: Wed, 08 May 2013 10:12:29 GMT < ETag: "780602-4f6-4db31b2978ec0" < Last-Modified: Thu, 25 Apr 2013 16:13:23 GMT < Content-Length: 1270
  • 17. Scale • Think about scale sooner that later • Rate limits • Extra servers • Partitioning • Caching • • • • Between application and database In the application itself Using an API proxy CDN for large static content
  • 18. Supporting multiple formats • To get the JSON format from a collection or specific element: • dogs.json • /dogs/1234.json Accept header for entity versioning also applicable Default format: JSON Follow JavaScript conventions
  • 19. Chatty APIs Imagine how developers will use your API • You can design a RESTful API and still mitigate the chattiness. Be complete and RESTful and provide shortcuts Take advantage of the partial response syntax • /owners/5678?fields=name, dogs.name
  • 25. Security • Use something established • API keys for non-sensitive data only • Username/password auth for site based APIs • OAuth for server-to-server APIs • SSL for EVERYTHING sensitive
  • 26. OAuth 1. An OAuth token gives one app access to one API on behalf of one user. 2. App developers do not want responsibility of holding a user’s secret information (password). 3. there are three entities (legs) – user/server/client
  • 27. Why is OAuth important? • What if client is hacked and someone steals all the passwords? • OAuth allows the API provider to revoke tokens for an individual user and for an entire app • On the other hand, if user decides to change his password, the token will be the same. • Developers can use an OAuth library in their language
  • 28. Types of OAuth 2.0 • BEARER TOKEN • SSL and big numbers • MAC TOKEN • Uses signature instead of SSL • SAML • if you and your potential API developers don’t understand SAML or know what it is, that’s a signal to stay away