Expose an API with json response
pAlright im using fosrestbundle with JMSSerializerBundle bundles. I tried
to following few tutorials but couldnt get this working. What i want is an
API exposed which returns a json structure. (Just like WCF). Here is what
i have tried:/p pController:/p precodelt;?php namespace
Lucky\RNDBundle\Controller; use
Symfony\Bundle\FrameworkBundle\Controller\Controller; use
Symfony\Component\HttpFoundation\Request; use FOS\RestBundle\View\View;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use
FOS\RestBundle\Controller\FOSRestController; use
FOS\RestBundle\Routing\ClassResourceInterface; use FOS\Rest\Util\Codes;
use JMS\Serializer\SerializationContext; class RestController extends
FOSRestController implements ClassResourceInterface { public function
getAction() { $em = $this-gt;getDoctrine()-gt;getManager(); $usersRepo =
$em-gt;getRepository('DABundle:Users'); $usersQuery =
$usersRepo-gt;createQueryBuilder('u') -gt;select('u.id') -gt;getQuery();
$users = $usersQuery-gt;execute(); if(!$users) { throw
$this-gt;createNotFoundException('No product found.'); } return array(
'entities' =gt; $users, ); } } #app/config/config.yml
sensio_framework_extra: view: annotations: false fos_rest:
param_fetcher_listener: true body_listener: true format_listener: true
view: view_response_listener: 'force' #app/config/routing.yml rest_users:
type: rest resource: RNDBundle/Controller/RestController prefix: /getusers
/code/pre pI honestly dont know where i should put the API url (Whether in
app/config/routing.yml or bundle/resources/config/routing.yml). Plus how i
can get the json response using Fiddler?/p pI have also tried to access
the url like /getusers but it says annot import resource
RNDBundle/Controller/RestController from
C:/wamp/www/lucky/app/config\routing.yml. (Class could not be determined
for Controller identified by RNDBundle/Controller/RestController.)/p
No comments:
Post a Comment