16.07.2017 Views

AngularJS Essentials

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

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

Now, if we want to obtain a specific car, we need to add some parameters to this<br />

URL, and again, the lack of standard makes things harder:<br />

GET /retrieveCar?carId=10 HTTP/1.1<br />

GET /getCar?idCar=10 HTTP/1.1<br />

GET /giveMeTheCar?car=10 HTTP/1.1<br />

Chapter 4<br />

Introduced a long time ago by Roy Fielding, the REST method, or Representational<br />

State Transfer, has become one of the most adopted architecture styles in the last few<br />

years. One of the primary reasons for all of its success is the rise of the AJAX-based<br />

technology and also the new generation of web applications, based on the frontend.<br />

It's strongly based on the HTTP protocol by means of the use of most of its methods<br />

such as GET, POST, PUT, and DELETE, bringing much more semantics and providing<br />

standardization.<br />

Basically, the primary concept is to replace the verbs for nouns, keeping the URLs as<br />

simple and intuitive as possible. This means changing actions such as retrieveCars,<br />

listCars, and even getCars for the use of the resource cars, and the method GET,<br />

which is used to retrieve information, as follows:<br />

GET /cars HTTP/1.1<br />

Also, we can retrieve information about a specific car as follows:<br />

GET /cars/1 HTTP/1.1<br />

The POST method is reserved to create new entities and also to perform complex<br />

searches that involve a large amount of data. This is an important point; we should<br />

always avoid transmitting information that might be exposed to encoded errors<br />

through the GET method, as long as it doesn't have a content type.<br />

This way, in order to create a new car, we should use the same resource, cars, but<br />

this time, with the POST method:<br />

POST /cars HTTP/1.1<br />

The car information will be transmitted within the request body, using the<br />

desired format. The major part of the libraries and frameworks works really well<br />

with JSON, also known as JavaScript Object Notation, which is a lightweight data<br />

interchange format.<br />

[ 77 ]<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!