-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
475 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# RESTful Webservices in Symfony | ||
|
||
## Coding Challenge 5 - Content Negotiation | ||
|
||
### Tasks | ||
|
||
- set the correct format option (JSON or XML) of the current Request | ||
- read the `Accept` request header and negotiate the content-type using Will Durand's negotiation library | ||
|
||
### Solution | ||
|
||
- require the willdurand/negotiation library: `composer require willdurand/negotiation` | ||
- create a `ContentNegotiator` class, use the `RequestStack` and implement a method to retrieve | ||
the negotiated request format (`json` should be the default request format) | ||
- create a `RequestFormatListener`, subscribe on the `kernel.request` event (priority: 8) and | ||
use the `ContentNegotiator` to set the request's request format | ||
- adjust all your Controllers, Normalizers and Data Transfer Objects to provide your representation of | ||
your resources in the format accepted by the client | ||
|
||
#### Hints | ||
|
||
You can get the best fitting format by using: | ||
|
||
``` | ||
$negotiator = new Negotiator(); | ||
$acceptHeader = $negotiator->getBest($request->getAcceptableContentTypes(), self::ACCEPTED_CONTENT_TYPES); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,23 +5,61 @@ | |
"firstname": "a", | ||
"lastname": "1", | ||
"email": "[email protected]", | ||
"workshops": [] | ||
"workshops": [], | ||
"_links": { | ||
"self": { | ||
"href": "\/workshops\/4878f198-36ab-4fe3-8189-19662a9764fa" | ||
}, | ||
"collection": { | ||
"href": "\/workshops" | ||
} | ||
} | ||
}, | ||
{ | ||
"identifier": "e942ce16-27c2-494f-9d93-03412da980c5", | ||
"firstname": "b", | ||
"lastname": "2", | ||
"email": "[email protected]", | ||
"workshops": [] | ||
"workshops": [], | ||
"_links": { | ||
"self": { | ||
"href": "\/workshops\/e942ce16-27c2-494f-9d93-03412da980c5" | ||
}, | ||
"collection": { | ||
"href": "\/workshops" | ||
} | ||
} | ||
}, | ||
{ | ||
"identifier": "4714fb8a-83d8-49af-abbf-7c68fc6c9656", | ||
"firstname": "c", | ||
"lastname": "3", | ||
"email": "[email protected]", | ||
"workshops": [] | ||
"workshops": [], | ||
"_links": { | ||
"self": { | ||
"href": "\/workshops\/4714fb8a-83d8-49af-abbf-7c68fc6c9656" | ||
}, | ||
"collection": { | ||
"href": "\/workshops" | ||
} | ||
} | ||
} | ||
], | ||
"total": 5, | ||
"count": 3 | ||
"count": 3, | ||
"_links": { | ||
"self": { | ||
"href": "\/attendees?page=1&size=3" | ||
}, | ||
"first": { | ||
"href": "\/attendees?page=1&size=3" | ||
}, | ||
"last": { | ||
"href": "\/attendees?page=2&size=3" | ||
}, | ||
"next": { | ||
"href": "\/attendees?page=2&size=3" | ||
} | ||
} | ||
} |
Oops, something went wrong.