What are RESTful Web Services. Detail Explanation
RESTful Web Services
Most WebServers today run Web services using a common stateless Web architecture known as REST, which stands for Representational State Transfer Architecture. Web services that offer this architecture are known as RESTful services. RESTful services are build using the standard Web components and protocols.
Requests are made to RESTful Web services in a standardised way via URIs.
URI vs. URL
- Uniform Resource Identifier
- URI can contain URL, document, image, file, services, email address or ISBN code.
- Uniform Resource Locator
- URI specifies the data you want
- A URL is a URI
- Ex. https://google.com?search=android
- we use URI or URL depending on the api we're calling
Each web services requests contains a URI and is transferred to our server using the same HTTP protocol that's used by Web browsers. Http requests contain an operation to tell the server what to do.
Common Http operations includes:
- GET - retrieving server data
- POST or PUT - updating the server with new data
- DELETE - delete data from the server
Server Response has formatted data
- XML
- json
example: Json response
[
{
"price": 45000,
"id": 4200,
"type": "buy",
"img_src": "http://my.buy.image.png"
},
{
"price": 55000,
"id": 9900,
"type": "rent",
"img_src": "http://my.rent.image.png"
}
]
- JSON Response is an array indicated by the square brackets.
- Array Contains objects which are surrounded by curly brackets.
- Each object contains a set of Name : Value pairs
- Name and value is separated by colon :
- Name is surrounded by quote and value can be string or int
Queries in URI
Queries are like function parameters. Almost any RESTful services will also accept query parameters as part of the URI.
Query parameters are separated from the location of the service by a question mark.
https://my.query.com/rent?type=car
?filterName=filterValue
Servers can define as many and whatever parameters it needs.
We use & character to separate between the parameters.
https://my.query.com/rent?type=car&price=20000&color=red
Follow my next tutorial to learn about RetroFit library to communicate with the Back-end services. The RetroFit library creates the URIs for the Web services based on parameters we pass to it so we can focus on app functionality.
Comments
Post a Comment