SlideShare une entreprise Scribd logo
1  sur  34
RESTful APIs: Tips &
Tricks
Maksym Bruner
April 5, 2018
I am:
• Solution Architect in EPAM
• Java developer with 10+ years of experience
(also .NET, PHP)
• Kharkiv JUG Program Committee Head
• Bar owner
Who am I?
What do we need tests for?
1. Why it matters and what we won't talk about
2. Quick tips - one page you can easily find in Internet
3. What is hard to find in Internet
4. What is nearly impossible to find and what nobody likes to talk about
5. Tools, tools, tools
6. Modern approaches for communication between backend and frontend
Agenda
What do we need tests for?
• HATEOAS – never seen
• Management solutions – different focus
• Implementation details – takes to much time
Not today
•API (Application Programming Interface) is a
traditional and well known integration method.
An approach to represent Business or IT assets and enable
and enable programmatic access to them
•Recently, the term “API” often implies Web API:
“Web APIs are the defined interfaces through which
interactions happen between an enterprise and applications
applications that use its assets” - Wikipedia
•In business context APIs are seen as one of the pillars
of digital business: they help in building the
automated business ecosystems also known as
WHAT IS AN API?
GET statuses/mentions_timeline
GET statuses/user_timeline
GET statuses/retweets_of_me
GET statuses/retweets/:id
GET statuses/show/:id
POST statuses/destroy/:id
POST statuses/update
POST statuses/retweet/:id
01001
10110 CORE
BUSINESS
WHAT?
HOW?
API CLASSIFICATIONS: WHAT TYPES OF APIs EXIST?
▶ Data
▶ Processes
▶ Things
ASSETS
▶ Private
▶ Partner
▶ Public
SCOPE
▶ Free
▶ Developer pays
▶ Developer gets paid
▶ Indirect
BUSINESS
MODEL
▶ Based on specification or standard (e.g.
FHIR, OData)
▶ Unique, non-standard
STANDAR
DS
▶ SOAP
WEB
SERVICES
▶ Hypermedia
▶ Pragmatic REST
REST
▶ Websockets
▶ Comet
▶ Web hooks
EVENT-
DRIVEN
TECHNOL
OGY
Simple task:
Implement 3 tier application for saved search service:
• User submits a query
• System generates search results – saved search
• User can view submitted queries and then view
results
• User can archive or delete saved search
Three teams:
• Frontend
• Backend
• DevOps
Workshop
What could go wrong?
• Paths, methods
• Data models
• Input parameters
• Actions
• Security
Efforts:
• 1 hour for discussing happy-path scenarios
• 1 hour for discussing exceptional cases
QUICK WINS
1. Nouns
GET /requests
GET /requests/new
GET /getRequests
2. GET and state
GET /users/123/activate -> activate
3. Plural nouns
GET /users
GET /user
4. Subresources
GET /users/123/activities
What you can find easily on the Internet?
5. Headers
Content-Type: application/json
Accept: appication/json, application/xml
6. Sorting and filtering
GET /cars?color=red
GET /cars?sort=+name,-age
7. Select fields
GET /cars?fields=name,color
8. Paging
GET /cars?limit=0&offset=10
What else?
10. Field names
Use camelCase that is a standard for JSON
11. Use error codes
2xx – ok
3xx – redirection
4xx – client error
5xx – server error
12. Versioning
/v1/cars
13. Shortcuts
/requests/closed
/notifications/last
14. Use or not use wrappers
{
count: 10,
list: [..]
}
15. Defaults for pagination and filtering
16. Authentication
WHAT IS NOT SO CLEAR THERE
What must be considered during design:
• How simple is to understand and ”Clean” design
• How to secure URI
• Usage scenarios and domain
• Caching
• Overlapping with other URIs
• REST requirements
Scenarios:
• View my requests
• View my requests (Support team)
• View requests from my department (Manager)
URI Structures
GET /requests
GET /requests?user_id={user_id}
GET /{user_id}/requests
GET /users/{user_id}/requests
GET /requests
X-User-Identifier: {user_id}
GET /support/requests
GET /requests/my
Cache-Control: private
GET /me/requests
Cache-Control: private
GET /requests/1234
--------------------
HTTP/1.1 200 OK
{
id: “1234”,
subject: “Password expired”,
categoryId: “22”,
created: …,
status: “APPROVED”,
assignee: {
id: “4321”,
name: “Amit Kumar”
}
}
Data models
POST /requests
{
subject: “Password expired”,
categoryId: “22”
}
--------------------
HTTP/1.1 201 Created
Location:
http://example.org/requests/1234
{
id: “1234”,
…
}
PUT /requests/1234
{
!!!
}
--------------------
PATCH /requests/1234
{
subject: “Password is expired”
}
--------------------
PATCH /requests/1234
[
{ subject: “Password is expired” },
{ tags: “3,45,121” },
]
Data models #2
GET /requests/1234/edits
--------------------
[
{
date: “2018-04-04T14:20:25.912Z”,
author: {
id: “513”,
name: “Rajeev Jane”
},
changes: [
{ subject: “Password is expired” },
{ tags: “3,45,121” },
]
},…
]
Prefer header
Applicable for:
• Different content schemas for GET requests
• return-minimal
• return-full
• Different return objects
• return-content
• return-status
• return-no-content
• Versioning
• Free format responses
Data models #3
HTTP/1.1 201 Created
Location: http://example.org/requests/1234
{
id: “1234”,
…
}
HTTP/1.1 201 Created
Location: http://example.org/requests/1234
{
status: ”ok”
}
HTTP/1.1 204 No Content
Location: http://example.org/requests/1234
Take into account:
• Caching must be proxy aware
• Aggressive caching might happen
• Header that might affect response content
Additional directives:
• max-age=<seconds> – overrides Expires header
• must-revalidate – forces resources validation
Examples:
Cache-Control: no-cache, no-store, must-revalidate
Cache-Control: public, max-age=31536000
What is eligible for:
• GET and HEAD
• 200, 203, 206, 300, 301, 410
Caching API Calls
Cache-
Control
Local
cache
Cache
anywhere
Revalidati
on
no-store no no n/a
private yes no no
no-cache yes yes yes
public yes yes no
If-Modified-Since != Last-Modified = 200
If-Modified-Since == Last-Modified = 304
If-None-Match != Etag = 200
If-None-Match == Etag = 304
HTTP/1.1 200 OK
Etag: “1234-1”
Last-Modified: Sat, 27 Jun 2015 11:03:32 GMT
Authentication methods:
• Basic
Authorization: Basic ZnJlZDpmcmVk
• API Key
X-API-Key: abcdef12345
• OAuth
Authorization: Bearer
pwwbkvv7abqzonnvztpea91ich7vprwdorbt4w4m
• OAuth JWT tokens
• OAuth scopes: granularity for permissions
• 54 scopes used by Slack API
• users.profile:read,
• users.profile:write
Security
Code Description
400 Bad
Request
Request cannot be processed. Used when
request contains unsupported parameters.
Also, used for validation errors or wrong
input format indication.
401
Unauthorized
Request requires authentication.
403 Forbidden
Access is not allowed to a requested
resource or operation.
404 Not Found Resource was not found.
500 Internal
Server Error
Error happened on server side. Default
handlers that provides such details as a
stack trace in response MUST be avoided.
Error design (including validation)
{
code: 1234,
message: “Validation failed”,
errors: [
{
field: “referenceEntityId”,
errorMessage: “Not found”
},
{
field: “name”,
errorMessage: “Name is required”
}
]
}
Use Content-Type for different schemas:
• application/json;profile=NoBodyError
• application/json;profile=NoParameterError
• application/json;profile=ValidationError
What else can be included:
• Link to documentation
• Error description
WHAT IS HARD TO FIND
Take care of:
• All possible workflows
• Linked resources
• Actors
• Domain model
Design tips:
• Try treating actions as resources
• Use PATCH with complex payloads
• Use headers for meta information
Complex actions
Context: IT support system
Use cases:
1 Re-assign request
2 Enrich extra request information
3 Clone request
4 Grant permission to view requests
5 Transfer to another system
6 Merge requests
7 Lock/unlcok request
8 Change status
9 skip
1 Re-assign request
2 Enrich extra request information
3 Clone request
Complex actions #2
1. PATCH /requests/{request_id}
{
assigneeId: <new_id>,
}
2. PUT /requests/{request_id}/environment {
{
osVersion: "MAC OS X...",
hardware: {…},
destination: "EXTERNAL NETWORK",
...
}
3. POST /requests
Content-Type: application/reference
X-Reference-Id: <requst_id>
X-Clone-Parameters: copy-attachments
4 Grant permission to view
requests
5 Transfer to another system
Complex actions #3
4. PATCH /requests/{request_id}/acl
{ userId: <user_id>, permissions: "view,edit” }
5. POST /legacy_support/transfers
{ requestId: “1234” }
201 Created
{
transferId: "321",
status: "TRANSFERED",
originalRequestId: "1234",
legacyRequestId: "90189",
legacyLink: "http://old.support.company.net/requests/ID-
90189"
}
GET /legacy_support/requests/90189
301 Moved Permanently
Location: http://old.support.company.net/requests/ID-90189
6 Merge requests
7 Lock/unlock request
Complex actions #4
7. PATCH /requests/{request_id}/lock_status
{
locked: true,
details: { comment: "Lock for audit" }
}
GET /requests/{request_id}/lock_status
{
locked: true,
lockedBy: "John Doe"
since: "2018-04-04T14:20:25.912Z"
details: {
comment: "Lock for audit"
}
}
PATCH /requests/{request_id}/lock_status
{ locked: false }
8 Change status
Complex actions #5
7. PATCH /requests/{request_id}/status
{
status: "CLOSED",
details: {
resolution: "RESOLVED",
comment: "Password was reset"
}
}
GET /requests/{request_id}/status/history
[
{
status: "CLOSED",
date: "2018-04-04T14:20:25.912Z",
changedBy: "John Doe"
},
{
status: "IN_PROGRESS",
date: "2018-04-03T14:20:25.912Z",
changedBy: "John Doe"
},…
]
Limitations:
• URL length
• Copy link
• Durability
• Caching results (client/server)
Additional considerations:
• Saved presets
• Saved queries
Complex searches
1. GET /requests?name=param&status=SUBMITTED
2. GET /requests?filter={query}
3. POST /requests/search
{
author: "John",
status: "SUBMITTED"
}
201 Created
{
searchId: "9876",
expire: "2018-04-10T14:20:25.912Z"
}
GET /requests/search/9876?limit=15&offset=30
200 OK
X-Total-Count: 253
...
1. Resources
2. Methods
3. Response Codes
4. Tags
5. Models
Design steps
6. Complex Actions
7. Pagination & Sorting
8. Security
9. Error Models
10. Examples
1.Control and monitoring
• Control what you publish
• Throttling
• Control changes
2.Versioning
• Use hard versioning by including API version to requests
• Use soft versioning: change responses by manipulating
headers
Development
TOOLS
• Declarative schema definition
• UI support
• Validation
• New 3.0 version released last
year
• Code generation
Swagger or Open API
Swagger Hub
Swagger Diff
type Author {
id: Int!
firstName: String
lastName: String
posts: [Post]
}
type Post {
id: Int!
title: String
author: Author
votes: Int
}
type Query {
author(id: Int!): Author
}
GraphQL
query PostsForAuthor {
author(id: 1) {
firstName
posts {
title
votes
}}}
--------------------
{
"data": {
"author": {
"firstName": "Tom",
"posts": [
{ "title": "Introduction to GraphQL",
"votes": 2 }
]
}
}}
What next?
Workshop (1 day):
• Define business case
• Go through iterative process and design API
• 10 steps
• From scratch to comprehensive design
• Implement according to specification
• Code generation
• Spring adaptation
• Deployment and access
What next?
Questions?

Contenu connexe

Tendances

In search of: A meetup about Liferay and Search 2016-04-20
In search of: A meetup about Liferay and Search   2016-04-20In search of: A meetup about Liferay and Search   2016-04-20
In search of: A meetup about Liferay and Search 2016-04-20Tibor Lipusz
 
AppSec 2007 - .NET Web Services Hacking
AppSec 2007 - .NET Web Services HackingAppSec 2007 - .NET Web Services Hacking
AppSec 2007 - .NET Web Services HackingShreeraj Shah
 
On-page SEO for Drupal
On-page SEO for DrupalOn-page SEO for Drupal
On-page SEO for DrupalSvilen Sabev
 
Apache Solr-Webinar
Apache Solr-WebinarApache Solr-Webinar
Apache Solr-WebinarEdureka!
 
Drupal security
Drupal securityDrupal security
Drupal securityJozef Toth
 
Introduction to Lucene & Solr and Usecases
Introduction to Lucene & Solr and UsecasesIntroduction to Lucene & Solr and Usecases
Introduction to Lucene & Solr and UsecasesRahul Jain
 
Introduction to Web Services
Introduction to Web ServicesIntroduction to Web Services
Introduction to Web ServicesJeffrey Anderson
 
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)Sam Bowne
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP TutorialLorna Mitchell
 
Tagging search solution design Advanced edition
Tagging search solution design Advanced editionTagging search solution design Advanced edition
Tagging search solution design Advanced editionAlexander Tokarev
 
Getting started with DSpace 7 REST API
Getting started with DSpace 7 REST APIGetting started with DSpace 7 REST API
Getting started with DSpace 7 REST API4Science
 
Struts2-Spring=Hibernate
Struts2-Spring=HibernateStruts2-Spring=Hibernate
Struts2-Spring=HibernateJay Shah
 
How to Do a Performance Audit of Your .NET Website
How to Do a Performance Audit of Your .NET WebsiteHow to Do a Performance Audit of Your .NET Website
How to Do a Performance Audit of Your .NET WebsiteDNN
 
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)Sam Bowne
 
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 2 of 3)
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 2 of 3)CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 2 of 3)
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 2 of 3)Sam Bowne
 
Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012Stephan Hochdörfer
 
Alfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy BehavioursAlfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy BehavioursJ V
 

Tendances (20)

In search of: A meetup about Liferay and Search 2016-04-20
In search of: A meetup about Liferay and Search   2016-04-20In search of: A meetup about Liferay and Search   2016-04-20
In search of: A meetup about Liferay and Search 2016-04-20
 
AppSec 2007 - .NET Web Services Hacking
AppSec 2007 - .NET Web Services HackingAppSec 2007 - .NET Web Services Hacking
AppSec 2007 - .NET Web Services Hacking
 
On-page SEO for Drupal
On-page SEO for DrupalOn-page SEO for Drupal
On-page SEO for Drupal
 
Apache Solr-Webinar
Apache Solr-WebinarApache Solr-Webinar
Apache Solr-Webinar
 
HTML5 hacking
HTML5 hackingHTML5 hacking
HTML5 hacking
 
Drupal security
Drupal securityDrupal security
Drupal security
 
Introduction to Lucene & Solr and Usecases
Introduction to Lucene & Solr and UsecasesIntroduction to Lucene & Solr and Usecases
Introduction to Lucene & Solr and Usecases
 
Introduction to Web Services
Introduction to Web ServicesIntroduction to Web Services
Introduction to Web Services
 
Intro apache
Intro apacheIntro apache
Intro apache
 
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
CNIT 129S: 13: Attacking Users: Other Techniques (Part 1 of 2)
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP Tutorial
 
Tagging search solution design Advanced edition
Tagging search solution design Advanced editionTagging search solution design Advanced edition
Tagging search solution design Advanced edition
 
Getting started with DSpace 7 REST API
Getting started with DSpace 7 REST APIGetting started with DSpace 7 REST API
Getting started with DSpace 7 REST API
 
Struts2-Spring=Hibernate
Struts2-Spring=HibernateStruts2-Spring=Hibernate
Struts2-Spring=Hibernate
 
Web crawler
Web crawlerWeb crawler
Web crawler
 
How to Do a Performance Audit of Your .NET Website
How to Do a Performance Audit of Your .NET WebsiteHow to Do a Performance Audit of Your .NET Website
How to Do a Performance Audit of Your .NET Website
 
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 1 of 2)
 
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 2 of 3)
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 2 of 3)CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 2 of 3)
CNIT 129S: 12: Attacking Users: Cross-Site Scripting (Part 2 of 3)
 
Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012Offline strategies for HTML5 web applications - pfCongres2012
Offline strategies for HTML5 web applications - pfCongres2012
 
Alfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy BehavioursAlfresco Content Modelling and Policy Behaviours
Alfresco Content Modelling and Policy Behaviours
 

Similaire à REST Api Tips and Tricks

Boost Your Content Strategy for REST APIs with Gururaj BS
Boost Your Content Strategy for REST APIs with Gururaj BSBoost Your Content Strategy for REST APIs with Gururaj BS
Boost Your Content Strategy for REST APIs with Gururaj BSInformation Development World
 
REST Methodologies
REST MethodologiesREST Methodologies
REST Methodologiesjrodbx
 
API-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptxAPI-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptxamarnathdeo
 
CNIT 129S: Ch 4: Mapping the Application
CNIT 129S: Ch 4: Mapping the ApplicationCNIT 129S: Ch 4: Mapping the Application
CNIT 129S: Ch 4: Mapping the ApplicationSam Bowne
 
Introduction to SoapUI day 1
Introduction to SoapUI day 1Introduction to SoapUI day 1
Introduction to SoapUI day 1Qualitest
 
Soap UI - Getting started
Soap UI - Getting startedSoap UI - Getting started
Soap UI - Getting startedQualitest
 
Restful风格ž„web服务架构
Restful风格ž„web服务架构Restful风格ž„web服务架构
Restful风格ž„web服务架构Benjamin Tan
 
Business Applications Integration In The Cloud
Business Applications Integration In The CloudBusiness Applications Integration In The Cloud
Business Applications Integration In The CloudAnna Brzezińska
 
James Higginbotham - API Design
James Higginbotham - API DesignJames Higginbotham - API Design
James Higginbotham - API DesignJohn Zozzaro
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiUnmesh Baile
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiUnmesh Baile
 
2019-04-17 Bio-IT World G Suite-Jira Cloud Sample Tracking
2019-04-17 Bio-IT World G Suite-Jira Cloud Sample Tracking2019-04-17 Bio-IT World G Suite-Jira Cloud Sample Tracking
2019-04-17 Bio-IT World G Suite-Jira Cloud Sample TrackingBruce Kozuma
 
Building Data Portals and Science Gateways with Globus
Building Data Portals and Science Gateways with GlobusBuilding Data Portals and Science Gateways with Globus
Building Data Portals and Science Gateways with GlobusGlobus
 
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)Yury Leonychev
 
Deep Dive on Accelerating Content, APIs, and Applications with Amazon CloudFr...
Deep Dive on Accelerating Content, APIs, and Applications with Amazon CloudFr...Deep Dive on Accelerating Content, APIs, and Applications with Amazon CloudFr...
Deep Dive on Accelerating Content, APIs, and Applications with Amazon CloudFr...Amazon Web Services
 
Building & Testing Scalable Rails Applications
Building & Testing Scalable Rails ApplicationsBuilding & Testing Scalable Rails Applications
Building & Testing Scalable Rails Applicationsevilmike
 

Similaire à REST Api Tips and Tricks (20)

Rest web services
Rest web servicesRest web services
Rest web services
 
Boost Your Content Strategy for REST APIs with Gururaj BS
Boost Your Content Strategy for REST APIs with Gururaj BSBoost Your Content Strategy for REST APIs with Gururaj BS
Boost Your Content Strategy for REST APIs with Gururaj BS
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
REST Methodologies
REST MethodologiesREST Methodologies
REST Methodologies
 
API-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptxAPI-Testing-SOAPUI-1.pptx
API-Testing-SOAPUI-1.pptx
 
CNIT 129S: Ch 4: Mapping the Application
CNIT 129S: Ch 4: Mapping the ApplicationCNIT 129S: Ch 4: Mapping the Application
CNIT 129S: Ch 4: Mapping the Application
 
Introduction to SoapUI day 1
Introduction to SoapUI day 1Introduction to SoapUI day 1
Introduction to SoapUI day 1
 
Soap UI - Getting started
Soap UI - Getting startedSoap UI - Getting started
Soap UI - Getting started
 
Cache Security- The Basics
Cache Security- The BasicsCache Security- The Basics
Cache Security- The Basics
 
Restful风格ž„web服务架构
Restful风格ž„web服务架构Restful风格ž„web服务架构
Restful风格ž„web服务架构
 
Business Applications Integration In The Cloud
Business Applications Integration In The CloudBusiness Applications Integration In The Cloud
Business Applications Integration In The Cloud
 
James Higginbotham - API Design
James Higginbotham - API DesignJames Higginbotham - API Design
James Higginbotham - API Design
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbai
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbai
 
2019-04-17 Bio-IT World G Suite-Jira Cloud Sample Tracking
2019-04-17 Bio-IT World G Suite-Jira Cloud Sample Tracking2019-04-17 Bio-IT World G Suite-Jira Cloud Sample Tracking
2019-04-17 Bio-IT World G Suite-Jira Cloud Sample Tracking
 
SharePoint 2013 - What's New
SharePoint 2013 - What's NewSharePoint 2013 - What's New
SharePoint 2013 - What's New
 
Building Data Portals and Science Gateways with Globus
Building Data Portals and Science Gateways with GlobusBuilding Data Portals and Science Gateways with Globus
Building Data Portals and Science Gateways with Globus
 
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)
 
Deep Dive on Accelerating Content, APIs, and Applications with Amazon CloudFr...
Deep Dive on Accelerating Content, APIs, and Applications with Amazon CloudFr...Deep Dive on Accelerating Content, APIs, and Applications with Amazon CloudFr...
Deep Dive on Accelerating Content, APIs, and Applications with Amazon CloudFr...
 
Building & Testing Scalable Rails Applications
Building & Testing Scalable Rails ApplicationsBuilding & Testing Scalable Rails Applications
Building & Testing Scalable Rails Applications
 

Dernier

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 

Dernier (20)

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 

REST Api Tips and Tricks

  • 1. RESTful APIs: Tips & Tricks Maksym Bruner April 5, 2018
  • 2. I am: • Solution Architect in EPAM • Java developer with 10+ years of experience (also .NET, PHP) • Kharkiv JUG Program Committee Head • Bar owner Who am I?
  • 3. What do we need tests for? 1. Why it matters and what we won't talk about 2. Quick tips - one page you can easily find in Internet 3. What is hard to find in Internet 4. What is nearly impossible to find and what nobody likes to talk about 5. Tools, tools, tools 6. Modern approaches for communication between backend and frontend Agenda
  • 4. What do we need tests for? • HATEOAS – never seen • Management solutions – different focus • Implementation details – takes to much time Not today
  • 5. •API (Application Programming Interface) is a traditional and well known integration method. An approach to represent Business or IT assets and enable and enable programmatic access to them •Recently, the term “API” often implies Web API: “Web APIs are the defined interfaces through which interactions happen between an enterprise and applications applications that use its assets” - Wikipedia •In business context APIs are seen as one of the pillars of digital business: they help in building the automated business ecosystems also known as WHAT IS AN API? GET statuses/mentions_timeline GET statuses/user_timeline GET statuses/retweets_of_me GET statuses/retweets/:id GET statuses/show/:id POST statuses/destroy/:id POST statuses/update POST statuses/retweet/:id 01001 10110 CORE BUSINESS
  • 6. WHAT? HOW? API CLASSIFICATIONS: WHAT TYPES OF APIs EXIST? ▶ Data ▶ Processes ▶ Things ASSETS ▶ Private ▶ Partner ▶ Public SCOPE ▶ Free ▶ Developer pays ▶ Developer gets paid ▶ Indirect BUSINESS MODEL ▶ Based on specification or standard (e.g. FHIR, OData) ▶ Unique, non-standard STANDAR DS ▶ SOAP WEB SERVICES ▶ Hypermedia ▶ Pragmatic REST REST ▶ Websockets ▶ Comet ▶ Web hooks EVENT- DRIVEN TECHNOL OGY
  • 7. Simple task: Implement 3 tier application for saved search service: • User submits a query • System generates search results – saved search • User can view submitted queries and then view results • User can archive or delete saved search Three teams: • Frontend • Backend • DevOps Workshop What could go wrong? • Paths, methods • Data models • Input parameters • Actions • Security Efforts: • 1 hour for discussing happy-path scenarios • 1 hour for discussing exceptional cases
  • 9. 1. Nouns GET /requests GET /requests/new GET /getRequests 2. GET and state GET /users/123/activate -> activate 3. Plural nouns GET /users GET /user 4. Subresources GET /users/123/activities What you can find easily on the Internet? 5. Headers Content-Type: application/json Accept: appication/json, application/xml 6. Sorting and filtering GET /cars?color=red GET /cars?sort=+name,-age 7. Select fields GET /cars?fields=name,color 8. Paging GET /cars?limit=0&offset=10
  • 10. What else? 10. Field names Use camelCase that is a standard for JSON 11. Use error codes 2xx – ok 3xx – redirection 4xx – client error 5xx – server error 12. Versioning /v1/cars 13. Shortcuts /requests/closed /notifications/last 14. Use or not use wrappers { count: 10, list: [..] } 15. Defaults for pagination and filtering 16. Authentication
  • 11. WHAT IS NOT SO CLEAR THERE
  • 12. What must be considered during design: • How simple is to understand and ”Clean” design • How to secure URI • Usage scenarios and domain • Caching • Overlapping with other URIs • REST requirements Scenarios: • View my requests • View my requests (Support team) • View requests from my department (Manager) URI Structures GET /requests GET /requests?user_id={user_id} GET /{user_id}/requests GET /users/{user_id}/requests GET /requests X-User-Identifier: {user_id} GET /support/requests GET /requests/my Cache-Control: private GET /me/requests Cache-Control: private
  • 13. GET /requests/1234 -------------------- HTTP/1.1 200 OK { id: “1234”, subject: “Password expired”, categoryId: “22”, created: …, status: “APPROVED”, assignee: { id: “4321”, name: “Amit Kumar” } } Data models POST /requests { subject: “Password expired”, categoryId: “22” } -------------------- HTTP/1.1 201 Created Location: http://example.org/requests/1234 { id: “1234”, … }
  • 14. PUT /requests/1234 { !!! } -------------------- PATCH /requests/1234 { subject: “Password is expired” } -------------------- PATCH /requests/1234 [ { subject: “Password is expired” }, { tags: “3,45,121” }, ] Data models #2 GET /requests/1234/edits -------------------- [ { date: “2018-04-04T14:20:25.912Z”, author: { id: “513”, name: “Rajeev Jane” }, changes: [ { subject: “Password is expired” }, { tags: “3,45,121” }, ] },… ]
  • 15. Prefer header Applicable for: • Different content schemas for GET requests • return-minimal • return-full • Different return objects • return-content • return-status • return-no-content • Versioning • Free format responses Data models #3 HTTP/1.1 201 Created Location: http://example.org/requests/1234 { id: “1234”, … } HTTP/1.1 201 Created Location: http://example.org/requests/1234 { status: ”ok” } HTTP/1.1 204 No Content Location: http://example.org/requests/1234
  • 16. Take into account: • Caching must be proxy aware • Aggressive caching might happen • Header that might affect response content Additional directives: • max-age=<seconds> – overrides Expires header • must-revalidate – forces resources validation Examples: Cache-Control: no-cache, no-store, must-revalidate Cache-Control: public, max-age=31536000 What is eligible for: • GET and HEAD • 200, 203, 206, 300, 301, 410 Caching API Calls Cache- Control Local cache Cache anywhere Revalidati on no-store no no n/a private yes no no no-cache yes yes yes public yes yes no If-Modified-Since != Last-Modified = 200 If-Modified-Since == Last-Modified = 304 If-None-Match != Etag = 200 If-None-Match == Etag = 304 HTTP/1.1 200 OK Etag: “1234-1” Last-Modified: Sat, 27 Jun 2015 11:03:32 GMT
  • 17. Authentication methods: • Basic Authorization: Basic ZnJlZDpmcmVk • API Key X-API-Key: abcdef12345 • OAuth Authorization: Bearer pwwbkvv7abqzonnvztpea91ich7vprwdorbt4w4m • OAuth JWT tokens • OAuth scopes: granularity for permissions • 54 scopes used by Slack API • users.profile:read, • users.profile:write Security
  • 18. Code Description 400 Bad Request Request cannot be processed. Used when request contains unsupported parameters. Also, used for validation errors or wrong input format indication. 401 Unauthorized Request requires authentication. 403 Forbidden Access is not allowed to a requested resource or operation. 404 Not Found Resource was not found. 500 Internal Server Error Error happened on server side. Default handlers that provides such details as a stack trace in response MUST be avoided. Error design (including validation) { code: 1234, message: “Validation failed”, errors: [ { field: “referenceEntityId”, errorMessage: “Not found” }, { field: “name”, errorMessage: “Name is required” } ] } Use Content-Type for different schemas: • application/json;profile=NoBodyError • application/json;profile=NoParameterError • application/json;profile=ValidationError What else can be included: • Link to documentation • Error description
  • 19. WHAT IS HARD TO FIND
  • 20. Take care of: • All possible workflows • Linked resources • Actors • Domain model Design tips: • Try treating actions as resources • Use PATCH with complex payloads • Use headers for meta information Complex actions Context: IT support system Use cases: 1 Re-assign request 2 Enrich extra request information 3 Clone request 4 Grant permission to view requests 5 Transfer to another system 6 Merge requests 7 Lock/unlcok request 8 Change status 9 skip
  • 21. 1 Re-assign request 2 Enrich extra request information 3 Clone request Complex actions #2 1. PATCH /requests/{request_id} { assigneeId: <new_id>, } 2. PUT /requests/{request_id}/environment { { osVersion: "MAC OS X...", hardware: {…}, destination: "EXTERNAL NETWORK", ... } 3. POST /requests Content-Type: application/reference X-Reference-Id: <requst_id> X-Clone-Parameters: copy-attachments
  • 22. 4 Grant permission to view requests 5 Transfer to another system Complex actions #3 4. PATCH /requests/{request_id}/acl { userId: <user_id>, permissions: "view,edit” } 5. POST /legacy_support/transfers { requestId: “1234” } 201 Created { transferId: "321", status: "TRANSFERED", originalRequestId: "1234", legacyRequestId: "90189", legacyLink: "http://old.support.company.net/requests/ID- 90189" } GET /legacy_support/requests/90189 301 Moved Permanently Location: http://old.support.company.net/requests/ID-90189
  • 23. 6 Merge requests 7 Lock/unlock request Complex actions #4 7. PATCH /requests/{request_id}/lock_status { locked: true, details: { comment: "Lock for audit" } } GET /requests/{request_id}/lock_status { locked: true, lockedBy: "John Doe" since: "2018-04-04T14:20:25.912Z" details: { comment: "Lock for audit" } } PATCH /requests/{request_id}/lock_status { locked: false }
  • 24. 8 Change status Complex actions #5 7. PATCH /requests/{request_id}/status { status: "CLOSED", details: { resolution: "RESOLVED", comment: "Password was reset" } } GET /requests/{request_id}/status/history [ { status: "CLOSED", date: "2018-04-04T14:20:25.912Z", changedBy: "John Doe" }, { status: "IN_PROGRESS", date: "2018-04-03T14:20:25.912Z", changedBy: "John Doe" },… ]
  • 25. Limitations: • URL length • Copy link • Durability • Caching results (client/server) Additional considerations: • Saved presets • Saved queries Complex searches 1. GET /requests?name=param&status=SUBMITTED 2. GET /requests?filter={query} 3. POST /requests/search { author: "John", status: "SUBMITTED" } 201 Created { searchId: "9876", expire: "2018-04-10T14:20:25.912Z" } GET /requests/search/9876?limit=15&offset=30 200 OK X-Total-Count: 253 ...
  • 26. 1. Resources 2. Methods 3. Response Codes 4. Tags 5. Models Design steps 6. Complex Actions 7. Pagination & Sorting 8. Security 9. Error Models 10. Examples
  • 27. 1.Control and monitoring • Control what you publish • Throttling • Control changes 2.Versioning • Use hard versioning by including API version to requests • Use soft versioning: change responses by manipulating headers Development
  • 28. TOOLS
  • 29. • Declarative schema definition • UI support • Validation • New 3.0 version released last year • Code generation Swagger or Open API
  • 32. type Author { id: Int! firstName: String lastName: String posts: [Post] } type Post { id: Int! title: String author: Author votes: Int } type Query { author(id: Int!): Author } GraphQL query PostsForAuthor { author(id: 1) { firstName posts { title votes }}} -------------------- { "data": { "author": { "firstName": "Tom", "posts": [ { "title": "Introduction to GraphQL", "votes": 2 } ] } }}
  • 33. What next? Workshop (1 day): • Define business case • Go through iterative process and design API • 10 steps • From scratch to comprehensive design • Implement according to specification • Code generation • Spring adaptation • Deployment and access What next?