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 />

}<br />

"location": "/docs/isfbook/Documents/Books/<strong>Spring</strong> Recepies.pdf",<br />

"description": "A <strong>Spring</strong> Recipes from Apress",<br />

"created": "2014-02-24",<br />

"modified": "2014-02-26"<br />

But how can you post this data? Well, there are different ways. One is using the CURL command line, like so:<br />

curl -X POST -H "Content-Type: application/json" -d '{"documentId": "03b94c89-c4e0-4144-90cea64ebaaea8b5","name":e":<br />

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

"Portable Document Format","extension": ".pdf"},"location": "/docs/isfbook/Documents/Books/<strong>Spring</strong><br />

recipes.pdf","description": "A <strong>Spring</strong> recipes from Apress","created": "2014-02-24","modified":<br />

"2014-02-26"}' http://localhost:8080/mydocuments/documents<br />

Another way is using an add-on from Firefox or any other browser that can do RESTful calls. Figure 12-3 shows<br />

the RESTClient add-on for Firefox and how to add a new document using the HTTP-POST method.<br />

Figure 12-3. RESTClient<br />

Once you press the Send button, it will POST your JSON document and it will insert it into the database.<br />

Regardless of which method you choose to POST the document, you can test it using the same method as Figure 12-1.<br />

179

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

Saved successfully!

Ooh no, something went wrong!