Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
9289dad7
Commit
9289dad7
authored
Jan 17, 2012
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[cookbook] implement some suggestions
parent
9c04345d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
doc/cookbook/json_request_body.rst
doc/cookbook/json_request_body.rst
+6
-6
No files found.
doc/cookbook/json_request_body.rst
View file @
9289dad7
...
@@ -57,9 +57,9 @@ replace the request data on the ``$request`` object.
...
@@ -57,9 +57,9 @@ replace the request data on the ``$request`` object.
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\ParameterBag;
$app->before(function (Request $request) {
$app->before(function (Request $request) {
if (0 === strpos($request->headers->get('Content-Type'), 'application/json') {
if (0 === strpos($request->headers->get('Content-Type'), 'application/json')
)
{
$data = json_decode($request->getContent(), true);
$data = json_decode($request->getContent(), true);
$request->request
= new ParameterBag
(is_array($data) ? $data : array());
$request->request
->replace
(is_array($data) ? $data : array());
}
}
});
});
...
@@ -74,16 +74,16 @@ return the post object, including its ``id``, as JSON.
...
@@ -74,16 +74,16 @@ return the post object, including its ``id``, as JSON.
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Response;
$app->
match
('/blog/posts', function (Request $request) {
$app->
post
('/blog/posts', function (Request $request) {
$post = array(
$post = array(
'title' => $request->get('title'),
'title' => $request->
request->
get('title'),
'body' => $request->get('body'),
'body' => $request->
request->
get('body'),
);
);
$post['id'] = createPost($post);
$post['id'] = createPost($post);
$json = json_encode($post);
$json = json_encode($post);
return new Response($json, 201);
return new Response($json, 201
, array('Content-Type' => 'application/json')
);
});
});
Manual testing
Manual testing
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment