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

Api Bundle Laravel Package

dyb/api-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require dyb/api-bundle:dev-master
    

    Add to AppKernel.php:

    new Dyb\ApiBundle\DybApiBundle(),
    
  2. Configuration: Add to config.yml:

    dyb_api:
        showcase:
            key: "your_api_key"
            secret: "your_api_secret"
    
  3. Routing: Include in routing.yml:

    dyb_showcase:
        resource: "@DybApiBundle/Controller/Showcase/"
        type: annotation
        prefix: /dyb/showcase/
    
  4. First Use Case: Access /dyb/showcase/list to fetch paginated user data or /dyb/showcase/choice for a selectable dropdown list.


Implementation Patterns

Core Workflow

  1. API Integration: Use the bundle’s built-in DybApiClient (if exposed) to interact with DoYouBuzz endpoints. Example:

    $client = $this->get('dyb.api.client'); // Hypothetical service
    $users = $client->getUsers(); // Assuming such a method exists
    
  2. Controller Usage: Leverage the pre-built ShowcaseController for basic CRUD-like operations (e.g., listing/choosing users). Extend or override methods for custom logic:

    // src/AppBundle/Controller/DybShowcaseController.php
    use Dyb\ApiBundle\Controller\ShowcaseController;
    
    class CustomShowcaseController extends ShowcaseController {
        public function listAction() {
            $users = parent::listAction(); // Reuse parent logic
            // Add custom filtering/logic
            return $this->render('custom_template.html.twig', ['users' => $users]);
        }
    }
    
  3. Twig Integration: Pass data to templates for rendering:

    {% for user in users %}
        <option value="{{ user.id }}">{{ user.firstname }} {{ user.lastname }}</option>
    {% endfor %}
    
  4. Service Layer: If the bundle lacks direct service access, create a custom service to wrap API calls:

    # services.yml
    services:
        dyb.api.user_service:
            class: AppBundle\Service\DybUserService
            arguments: ['@dyb.api.client'] # Hypothetical client
    

Gotchas and Tips

Pitfalls

  1. Deprecated Symfony 2:

    • The bundle targets Symfony 2.1, which may conflict with modern Laravel (or Symfony 4+/5+) dependencies. Test thoroughly in a legacy environment if needed.
  2. No Laravel Support:

    • This is a Symfony bundle, not Laravel-compatible. Use only in Symfony projects or via a bridge (e.g., Symfony Bridge).
  3. Undocumented API:

    • The README lacks details on:
      • How to extend the ShowcaseController.
      • Custom endpoint support (e.g., non-user data).
      • Error handling (e.g., invalid API keys/secrets).
    • Workaround: Reverse-engineer the ShowcaseController or contact DoYouBuzz for undocumented features.
  4. Hardcoded Routes:

    • Routes are fixed (/dyb/showcase/*). Override them in routing.yml if conflicts arise:
      dyb_custom_showcase:
          resource: "@DybApiBundle/Controller/Showcase/"
          prefix: /custom/dyb/
      
  5. No Rate Limiting:

    • The bundle doesn’t handle API rate limits. Implement middleware or a decorator for retries:
      // Example: Decorate the client service
      $client = new RateLimitedApiClient($originalClient, 10); // 10 requests/min
      

Debugging Tips

  1. API Key/Secret Validation:

    • If endpoints return 401/403, verify config.yml values and DoYouBuzz account permissions (Partner vs. Application access).
  2. cURL Dependencies:

    • Ensure your local web server has curl enabled. Test with:
      php -m | grep curl
      
  3. Logging:

    • Add debug logs to the ShowcaseController to inspect raw API responses:
      use Psr\Log\LoggerInterface;
      
      public function listAction(LoggerInterface $logger) {
          $response = $this->getApiResponse();
          $logger->debug('Raw API Response:', [$response]);
          // ...
      }
      

Extension Points

  1. Custom Endpoints:

    • Extend the bundle by creating a new controller/service for unsupported endpoints:
      // src/AppBundle/Controller/DybCustomController.php
      class DybCustomController extends Controller {
          public function customAction() {
              $client = $this->get('dyb.api.client');
              $data = $client->request('GET', '/custom/endpoint', ['param' => 'value']);
              return new JsonResponse($data);
          }
      }
      
  2. Response Transformation:

    • Override Twig templates or add a response transformer service:
      // src/AppBundle/Service/DybResponseTransformer.php
      class DybResponseTransformer {
          public function transform(array $data): array {
              return array_map(function($user) {
                  $user['full_name'] = "{$user['firstname']} {$user['lastname']}";
                  return $user;
              }, $data);
          }
      }
      
  3. Event Listeners:

    • Hook into API responses/events (if the bundle dispatches them). Example:
      # services.yml
      services:
          dyb.api.event_listener:
              class: AppBundle\EventListener\DybApiListener
              tags:
                  - { name: kernel.event_listener, event: dyb.api.response, method: onResponse }
      
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity