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
<?php | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
require_once __DIR__.'/../vendor/autoload.php'; | |
$app = new Silex\Application(); | |
$app['debug'] = true; |
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
{ | |
"is-json": true, | |
"getcontent-type-before-replace": "string", | |
"getcontent-before-replace": "{ \"id\": \"1234\", \"name\": \"john doe\" }", | |
"conversion-success": true, | |
"data-type-after-conv": "array", | |
"data-after-conv": { | |
"id": "1234", | |
"name": "john doe" | |
}, |
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
<script type="text/javascript"> | |
$(function() { | |
$('#testform').submit(function() { | |
$.ajax({ | |
type: "POST", | |
contentType: "application/json; charset=utf-8", | |
dataType: "json", | |
url: "{{ url('home') }}foo", | |
data: '{ "id": "1234", "name": "John Doe" }' |
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
{ | |
"require": { | |
"silex/silex": "1.0.*@dev", | |
"symfony/security": "2.1.*", | |
"symfony/monolog-bridge": "2.1.*", | |
"symfony/twig-bridge": "2.1.*", | |
"monolog/monolog": ">=1.0.0,<1.2-dev", | |
"twig/twig": ">=1.2.0,<2.0-dev", | |
"doctrine/dbal": ">=2.2.0,<2.4.0-dev", | |
"swiftmailer/swiftmailer": "4.1.*", |
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
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
$app->before(function (Request $request) use($app) { | |
if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) { | |
$data = json_decode($request->getContent(), true); | |
if (null === $data) { | |
return new Response('{"message":"Problems parsing JSON"}', 400); | |
} | |
$newRequest = new Request( |