Mobile Dev - Chapter 5
Mobile Dev - Chapter 5
Web Services
UDDI
Universal Description, Discovery and Integration.
UDDI is an XML based framework for describing,
discovering, and integrating web services.
WSDL
Web Services Description Language.
WSDL is an XML document containing
information about web services such as method
name, method parameter, and how to access it.
SOAP EXAMPLE
WEB API
An application programming
SERVICES interface (or API for short) is a
software component that enables
A web service is a resource that is
two otherwise unrelated applications
available over the internet
to communicate with each other
INTRODUCTION TO REST
WHAT IS REST?
REST stands for REpresentational State Transfer
Use GET requests to Use POST APIs to Use PUT APIs As the name applies,
only retrieve remote create new resources primarily to update DELETE APIs delete
resources an existing resource the resources
HEAD PATCH
OPTIONS
PATCH only does
TRACE
partial updates
CONNECT
REST CRUD
REST Resources
A resource can be a singleton or a collection. Ex: customers is a
collection resource and customer is a singleton resource (in a banking
domain).
SOAP
REST
SOAP is a protocol REST is an architectural style
SOAP cannot make use of REST REST can make use of SOAP
SOAP uses service interfaces to expose its functionality REST uses Uniform Service locators to access
to client applications the components on the hardware device.
SOAP requires more bandwidth for its presentation REST messages is lightweight
SOAP can only work with XML format. As seen from REST permits different data formats such as
SOAP messages, all data passed is in XML format. Plain text, HTML, XML, JSON, etc.
Support Stateful operations and security mechanisms Support caching
DESIGN A REST API
Idempotent REST APIs
It should not matter if the method has been called only once, or
ten times over. The result should always be the same.
GET PUT DELETE
PATCH
ARE IDEMPOTENT
POST
IS NOT IDEMPOTENT
REST Resources
A resource can be a singleton or a collection. Ex: customers is a
collection resource and customer is a singleton resource (in a banking
domain).
RESTful URI should refer to a resource that is a thing (noun) instead of referring to an action (verb)
because nouns have properties that verbs do not have – similarly, resources have attributes
http://api.example.com/device-management/managed-devices
http://api.example.com/device-management/managed-devices/{device-id}
http://api.example.com/user-management/users
Ex: A blog post might have their comments, so to retrieve these comments, an endpoint like
https://mysite.com/posts/{postId}/comments would make sense.
REST Best practices
Because HTTP methods such as GET, POST, PUT, PATCH, and DELETE are already in verb form for
performing basic CRUD (Create, Read, Update, Delete) operations, the endpoints should use nouns,
signifying what each of them does.
To ensure the client interprets JSON data correctly, you should set the Content-Type type in the response
header to application/json while making the request.
REST Best practices
GET requests over collection resources can potentially return a large number of items. You should design
a web API to limit the amount of data returned by any single request.
Ex: /orders?limit=25&offset=50
REST APIs should have different versions, so you don’t force clients (users) to migrate to new versions.
This might even break the application if you're not careful.
Many RESTful APIs from tech giants and individuals usually comes like this:
https://mysite.com/v1/ for version 1
https://mysite.com/v2 for version 2
REST Best practices
To eliminate confusion for API users when an error occurs, we should handle errors gracefully and return
HTTP response codes that indicate what kind of error occurred.
We can add caching to return data from the local memory cache instead of querying the database to
get the data every time we want to retrieve some data that users request. The good thing about caching
is that users can get data faster. However, the data that users get may be outdated.
When you make a REST API, you need to help clients (consumers) learn and figure out how to use it
correctly. The best way to do this is by providing good documentation for the API.
One of the most common tools you can use for API documentation is Swagger. And you can also use
Postman, one of the most common API testing tools in software development, to document your APIs.
Any question?
MSc. Hoang Le Hai Thanh