Rest Api
Rest Api
REST Architecture
====================
1) Provider / Resource
2) Consumer / Client
-> HTTP protocol will act as mediator between Consumer and Provider
-> Consumer and Provider will exchange data in the form XML / JSON
1) Http Request
2) Http Response
3) HTTP Methods
4) HTTP Status Codes
3>Request Parameter:-- To pass primitive data (like id, name, codes … etc)
as input, request parameters are used.
=>format looks like url?key=val&key=val…
=>Both key and value are String type by default.
Difference between PUT and Patch :
PUT :-- It indicates modify complete (full) data, based on
Identity (ID-PK).
PATCH :-- It indicates modify partial (few data, based on
Identity (ID-PK).
Request Parameter: Format:--
@RequestParam(
value="key",
required=true/false,
defaultValue="-value-")
DataType localVariable
====================================
JSON (Java Script Object Notation)
====================================
=> JSON is used to represent data in key-value format
=> JSON is universal format to exchange data over internet
Synax:
{
"id" : 101,
"name" : “Suresh",
"gender" : "Male",
"phno" : 463413
"address" : {
"city" : “Mysore",
"state" : “Karnataka"
}
}
@RestController : To represent java class as Distributed Component