25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 12 ■ Exposing a REST API<br />

Next, find a document. You can use the following ID: 431cddbf-f3c0-4076-8c1c-564e7dce16c9. Go to the<br />

browser and use the following URL: http://localhost:8080/mydocuments/documents/431cddbf-f3c0-4076-8c1c-<br />

564e7dce16c9. Figure 12-2 shows the result.<br />

Figure 12-2. http://localhost:8080/mydocuments/documents/431cddbf-f3c0-4076-8c1c-564e7dce16c9<br />

HTTP-POST<br />

Next, you need to add a new document. The REST call will use the HTTP-POST method and it is necessary to indicate<br />

that you are going to send a Content-Type:"application/json" on the header, and then pass the document as a<br />

JSON format. The following JSON can be used as a new document:<br />

{<br />

"documentId": "03b94c89-c4e0-4144-90ce-a64ebaaea8b5",<br />

"name": "<strong>Spring</strong> Recipes.pdf",<br />

"type": {<br />

"typeId": "41e2d211-6396-4f23-9690-77bc2820d84b",<br />

"name": "PDF",<br />

"desc": "Portable Document Format",<br />

"extension": ".pdf"<br />

},<br />

178

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!