I place my learning process in this document with 2 motives:
- To have a quick guide whenever I lost the track of knowledge.
- To share the knowledge with anyone wants to learn RESTful APIs
<?php | |
namespace App\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |
use Symfony\Component\HttpFoundation\Response; | |
use App\Entity\Product; | |
class ProductController extends AbstractController |
{% extends 'base.html.twig' %} | |
{% block body %} | |
<h1> Produtos </h1> | |
<hr> | |
<ul> | |
{% for p in products %} | |
<li> | |
Nome: {{p.name}} | |
- Preço: R$ {{p.price|number_format(2, ',', '.')}} |
# This file is auto-generated during the composer install | |
parameters: | |
database_host: 127.0.0.1 | |
database_port: null | |
database_name: api_sf | |
database_user: root | |
database_password: null | |
mailer_transport: smtp | |
mailer_host: 127.0.0.1 | |
mailer_user: null |
{ | |
"autoload": { | |
"psr-4": { | |
"AppBundle\\": "src/AppBundle", | |
"APIBundle\\": "src/APIBundle" | |
}, | |
"classmap": [ | |
"app/AppKernel.php", | |
"app/AppCache.php" | |
] |
api: | |
resource: "@APIBundle/Controller/" | |
type: annotation | |
prefix: /api | |
defaults: | |
_format: json | |
app: | |
resource: '@AppBundle/Controller/' | |
type: annotation |
<?php | |
namespace APIBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
class DefaultController extends Controller | |
{ |
<?php | |
namespace APIBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* Beer | |
* | |
* @ORM\Table(name="beers") |
<?php | |
namespace APIBundle\Controller; | |
use APIBundle\Entity\Beer; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Symfony\Component\HttpFoundation\Response; | |
/** |
<?php | |
namespace App\Form; | |
use App\Entity\User; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolver; | |
class UserType extends AbstractType |