2. Restful Webservices
- History
- What is webservices?
- Resource-Oriented Architecture
- HTTP methods
- Restful API design
- References
3. History
- Before 1999, people used to use SOAP to
integrate APIs.
- In 2000, REST was defined by Roy
Fielding in his PhD dissertation
"Architectural Styles and the Design of
Network-based Software Architectures"
4. History
- Properties:
- Scalability: to support large numbers of components and interactions among components.
- Simplicity of a Uniform Interface
- Modifiability of components to meet changing needs (even while the application is running)
- Portability of components by moving program code with the data
- Constraints:
- Client-Server
- Stateless: Each request from any client contains all the information necessary to service the
request
- Cacheable: Responses must, implicitly or explicitly, define themselves as cacheable, or not, to
avoid unsuitable response.
- Layered System: A client cannot ordinarily tell whether it is connected directly to the end
server, or to an intermediary along the way.
5. What is Restful Webservices?
- Representational state transfer (REST) or RESTful Web services are one way
of providing interoperability between computer systems on the Internet.
- Fielding used REST to design HTTP 1.1
6. Resource-Oriented Architecture
- In software engineering, a resource-oriented architecture (ROA) is a style of
software architecture and programming paradigm for designing and
developing software in the form of resources with "RESTful" interfaces.
7. HTTP methods
- HTTP implements REST, and we’re using HTTP to provide our restful
webservices.
HTTP Method Operation Note
POST Create It creates a new instance, it returns 201 code
PUT Update/Replace It updates or replaces the entire instance, it returns 200.
GET Read It reads from the server, it returns http code 200
PATCH Update/Modify It updates specific thing inside the instance, it returns 200
DELETE Remove It removes an instance, it returns 200
8. Restful API design
- It’s all about resources, REST tries to make every resource is a unique
location.
- URI: is used to locate the resource.
- To get tulip1 image in hard drive: /images/tulip1.jpg
9. Restful API design
Suppose we have the following Object:
User
Name: String
SSN: String
Job: String
addresses:
Address
Street: String
Building: String
Apartment: String
10. Restful API design - Moving from Verbs to Nouns
- Old API: getUser.
- Verb (get) + resource name(User)
- Old API: createUser.
- Verb(create) + resource name(User)
- Old API: deleteUser.
- Verb(delete) + resource name(User)
- Old API: updateUser.
- Verb(update) + resource name(user)
- HTTP provides the method name, your turn to provide the resource name:
- GET: /User/userId
- POST: /User
- DELETE: /User/userId
- PUT: /User/userId
11. Restful API design - More
- Old API: getUserAddress.
- Verb (get) + resource name(UserAddress)
- Old API: createUserAddress.
- Verb(create) + resource name(UserAddress)
- Old API: deleteUserAddress.
- Verb(delete) + resource name(UserAddress)
- Old API: updateUserAddress.
- Verb(update) + resource name(userAccont)
- HTTP provides the method name, your turn to provide the resource name:
- GET: /User/userId/addresses
- POST: /user/userId/addresses
- DELETE: /user/userId/adresses/id
- PUT: /User/userId/adresses