Tuesday, 17 September 2019

Rest Web Services


Rest and HTTP-
  • resource based uri
  • http methods
  • HTTP status code
  • Message Headers




Every time you load a web page you make a http request and you will get http response.
                Clientß  Server
                                Http response
it is Resource based URI-
           like- myapp.com/zipcode/12345

As like things are already there and you are looking it up rather than doing any action.

Http Methods –
                Now you have decided what the address is how you interact with it.
Http has methods or verbs that you can use to interact with rules.
GET
POST
PUT
DELETE

Good restful API must have right choices for right methods.

Metadata –
Now we tell the client what the address is and what http method we will use to call that address.
Now when they make a call what will be the response they get
Http defines status code, response headers, extra data like meta data.

Http Status code –
                Success – return 200
                Error – return 500
No found -404
In restful web services we cannot send messages because clients peace of code. so you will send status code.

Format of

                  client    ⏪⏪⏪       webservice
                          
                                metadata
                                     🔻
                                    data

Message Headers
 Content Type
text/xml
application/json

In web services you don’t have to struggle to find URI


Resource based uri
/profiles/dev

to make this generic
/profiles/{profileName}

And that is you have to do .think of resources and create a unique uri for them.


Uri tells what entity or what resource is being operated upon. and method tells operations.

get➤/products/10
delete➤/order/20

getting a message

get➤/message/{messageid}

updating a message

put➤/message/{messageId}

Why put not post?
Because content need to be send body of the put message.it replace message with new content.

When a post happens on collection uri it creates a new resource and then response is going to be resource id.






No comments:

Post a Comment

Note: only a member of this blog may post a comment.