|
|
|
@ -1465,16 +1465,16 @@ a Nette extension which makes integration of Doctrine 2 very straightforward.
|
|
|
|
|
|
|
|
|
|
A typical scenario for handling an API request is matching the HTTP request with
|
|
|
|
|
a corresponding handler routine which creates a response object, that is then
|
|
|
|
|
sent back to the client, encoded with JSON. The Nette\Application package can be
|
|
|
|
|
used to achieve this with Nette, although it is meant to be used mainly in MVP
|
|
|
|
|
applications.
|
|
|
|
|
sent back to the client, encoded with JSON. The `Nette\Application` package can
|
|
|
|
|
be used to achieve this with Nette, although it is meant to be used mainly in
|
|
|
|
|
MVP applications.
|
|
|
|
|
|
|
|
|
|
Matching HTTP requests with handlers can be done using standard Nette URL
|
|
|
|
|
routing -- we will create a Nette route for each API endpoint. Using the routing
|
|
|
|
|
mechanism from Nette logically leads to implementing handler routines as Nette
|
|
|
|
|
Presenter actions. Each presenter should serve logically related endpoints.
|
|
|
|
|
|
|
|
|
|
The last step is encoding the response as JSON. In Nette\Application, HTTP
|
|
|
|
|
The last step is encoding the response as JSON. In `Nette\Application`, HTTP
|
|
|
|
|
responses are returned using the `Presenter::sendResponse()` method. We decided
|
|
|
|
|
to write a method that calls `sendResponse` internally and takes care of the
|
|
|
|
|
encoding. This method has to be called in every presenter action. An alternative
|
|
|
|
|