Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Easy Api Bundle Laravel Package

citizen63000/easy-api-bundle

View on GitHub
Deep Wiki
Context7

easy-api-bundle

Symfony bundle to easily make api, inspired by work of DarwinOnLine

CRUD controllers :

Exemple :

/**
 * @Route("/my-path", name="my_path")
 * @OA\Tag(name="MyEntity")
 */
class MyEntityCrudController extends AbstractApiController
{
    public const entityClass = MyEntity::class;
    public const entityCreateTypeClass = MyEntityType::class;
    public const entityUpdateTypeClass = MyEntityType::class;
    public const serializationGroups = ['my_entity_full'];
    public const listSerializationGroups = ['my_entity_light'];
    public const filterFields = [];
    public const filterSortFields = [];
    
    use CrudControllerTrait;
}

CRUD routing :

Example:

api_my_path:
  resource: "@AppBundle/Controller/MyContext/MyController.php"
  type: annotation

Configuration (everything is optionnal) :

easy_api:
  authentication: true
  user_class: AppBundle\Entity\User\User
  user_tracking :
    enable: false
    connection_history_class: AppBundle\Entity\User\ConnectionHistory
  inheritance:
    entity: 'App\Entity\AbstractEntity'
    entityReferential: 'App\Entity\AbstractReferential'
    form: 'App\Form\Type\AbstractCoreType'
    repository: 'App\Form\Type\AbstractRepository'
    controller: 'App\Controller\AbstractApiController'
    serialized_form: 'App\Form\Model\SerializedForm'
  tests:
    debug: true # true by default
    datetime_format: 'Y-m-d H:i:s' # DateTimeInterface::ATOM format by default

Form options for frontend apps :

You can specify some options in attr field of form fields:

  • group : to group fields
  • discriminator
  • other options you want to pass

API-DOC Annotations

You can use all annotations of the nelmio api bundle. The DoctrineAnnorationReader cannot read self and static constants but with this bundle you can use it as strings in two cases as long as the issue isn't closed :

In Nelmio model annotation:

    /**
     * Get entity.
     *
     * @OA\Annotations\Response(
     *     response=200,
     *     description="Successful operation",
     *     @OA\Annotations\Schema(
     *          ref=@Nelmio\ApiDocBundle\Annotation\Model(
     *              type="static::entityClass",
     *              groups={"static::serializationGroups"}
     *          )
     *      )
     * ),
     * @param Request $request
     *
     * @return Response
     */
    public function getAction(Request $request)
    {
        ...
    }

And in an annotation named "GetFormParameter" which allows you to generate api-doc of form fields as get parameters :

     /**
      * List entities.
      *
      * @EasyApiBundle\Annotation\GetFormParameter(type="static::entitySearchTypeClass")
      * ...
      */
    public function listAction(Request $request)
    {
        ...       
    }

Test framework

User assertion:

Define it in php static::$additionalAssessableFunctions and implement it, with good parameters :

static::$additionalAssessableFunctions = ['assertMyAssertion'];
...
/**
* @param $key The key in response
* @param $parameter The parameter passed (optionnal)
* @param $value The value in response
*/
protected static function assertMyAssertion($key, $parameter, $value): void
{
    $parameter = $parameter ?? 'John';
    $expected = "hello world $parameter";
    $errorMessage = "Invalid value for {$key} field: expected {$expected}, get {$value}";
    static::assertTrue($expected === $value, $errorMessage);
}

Performance optimization

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware