Java Reference
In-Depth Information
PUT : Replace the entire collection with a new one, replace the resource element with a new
one, or create a resource element if its identifier does not exist.
POST : Create a new entry in a collection, or create a new entry in a resource element (less
commonly used).
DELETE : Delete an entire collection or a resource element.
Unlike SOAP, REST does not have an official standard, so different APIs may apply different conven-
tions in terms of how they deal with the HTTP methods listed previously. Additionally, REST does not
specify a formatting language or standard for the actual request and response messages to represent
data, which means that the server may answer the GET /books/B101 query shown previously with a
JSON, YAML, XML or even plain English description of the topic. Some developers choose to sup-
port multiple formats, either by using and adhering to the “Accept” header in the HTTP request, or by
adding an extension prefix to the requested URI, for example, GET /books/B101.xml .
Nowadays, companies such as Twitter, Facebook, and PayPal are all providing a REST interface
to access their services, information, and functionalities (Facebook calls this their “Graph API,”
but it works the same way). Due to the fact that there is no real REST standard, conventions might
differ among implementations—so you will need to browse through the API documentation of
each service you want to access—but they all agree on using simple HTTP‐based request‐response
communication.
Accessing Facebook's reSt Interface
try it out
This small exercise illustrates how RESTful web services are defined on top of simple HTTP requests.
1.
Navigate to http://graph.facebook.com/me with your web browser.
2.
You should receive the following reply:
{
"error": {
"message": "An active access token must be used to query information
about the current user.",
"type": "OAuthException",
"code": 2500
}
}
How It Works
Here's how it works:
1.
Navigating to http://graph.facebook.com/me with a web browser will result in the browser
executing an HTTP GET request for the /me endpoint.
2.
Facebook uses JSON to format its REST replies.
3.
As can be read from the reply, the server refuses to provide you with any information, as you have
not authenticated yourself first. Most RESTful web services nowadays use the so‐called “OAuth”
validation technology to perform the authentication step.
Search WWH ::




Custom Search