Installation
Add the package to your composer.json under require:
"ais/haribundle": "dev-master"
Run composer update.
Register the Bundle
Add Ais\HariBundle\AisHariBundle() to your AppKernel.php under registerBundles().
Ensure NelmioApiDocBundle, FOSRestBundle, and JMSSerializerBundle are also registered.
Configure Routing
Add the following to app/config/routing.yml:
ais_haris:
type: rest
prefix: /api
resource: "@AisHariBundle/Resources/config/routes.yml"
Access API Docs
Navigate to /api/doc in your dev environment (e.g., http://localhost/web/app_dev.php/api/doc).
GET request to /api/haris to fetch a list of Hari resources.Hari Entity Management
@Route, @QueryParam, @View) to define Hari-related API endpoints.use FOS\RestBundle\Controller\Annotations as Rest;
use Ais\HariBundle\Entity\Hari;
class HariController extends Controller
{
/**
* @Rest\Get("/haris")
* @Rest\View()
*/
public function getHarisAction()
{
$haris = $this->getDoctrine()->getRepository(Hari::class)->findAll();
return $haris;
}
}
Serialization with JMS
use JMS\Serializer\Annotation as Serializer;
class Hari
{
/**
* @Serializer\Type("string")
*/
private $name;
}
API Documentation
config.yml:
nelmio_api_doc:
documentation:
info:
title: Hari API
description: API for Hari resources
Integration with Doctrine
use Gedmo\Mapping\Annotation as Gedmo;
class Hari
{
/**
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
}
HariManager (if provided) into services for Hari-specific logic.prePersist, postRemove).use Symfony\Component\Validator\Constraints as Assert;
class Hari
{
/**
* @Assert\NotBlank
*/
private $name;
}
Symfony 2.7 Legacy
Missing Documentation
routes.yml and Entity/ directory.Dependency Conflicts
FOSRestBundle@dev, NelmioApiDocBundle@dev, and JMSSerializerBundle@dev may conflict with newer versions.composer.json or use replace:
"replace": {
"friendsofsymfony/rest-bundle": "2.8.0",
"nelmio/api-doc-bundle": "2.18.0"
}
No Hari Entity Defined
Hari entity exists but doesn’t provide one. Create it manually:
php app/console generate:doctrine:entity --entity="Hari"
Enable Profiler
/profiler) to inspect Hari-related requests/responses.Check Routes
php app/console debug:router | grep hari
Log Hari Actions
monolog:
handlers:
hari_handler:
type: stream
path: "%kernel.logs_dir%/hari.log"
level: debug
channels: [hari]
Custom Hari Services
services:
ais.hari.custom_service:
class: AppBundle\Service\CustomHariService
arguments: ["@ais.hari.manager"]
Override Templates
AisHariBundle/Resources/views/ to AppBundle/Resources/AisHariBundle/views/.Add Hari Commands
php app/console generate:bundle --namespace="AppBundle/Command" --format=yml --dir="src/AppBundle/Command"
$form = $this->createFormBuilder($hari)
->add('name', TextType::class)
->getForm();
HWIOAuthBundle or LexikJWTAuthenticationBundle for secure Hari APIs.LiipFunctionalTestBundle.How can I help you explore Laravel packages today?