Statistics
5816
10
15
17h
Badges
Tags
api
Dependencies

API

💥 Powerful API (PSR-7, REST, Relay, Middleware, GraphQL, DataQL, Annotations) for Nette Framework.


Build Status Code coverage Licence

Downloads this Month Downloads total Latest stable

Discussion / Help

Join the chat

Install

composer require contributte/api

Version

State Version Branch PHP
development dev-master master >= 5.6
stable ^0.3.0 master >= 5.6

Prolog

This really powerful annotation-based API library is build on top of the PSR-7 standard. It reuses immutable Request & Response objects. It's well known that Presenters are the alpha and the omega in Nette applications. The presenters are not very suitable for API requests.

We have taken an idea from Java (Spring Framework) and many others and together we have created a Controller-based API. With full annotation support.

Controllers are small objects which can be registered in DIC as services (same as Presenters). They have a few public annotated methods. If one of the methods is matched by a router, it is called with ApiRequest and ApiResponse passed objects.

That's all. Take a look, it's really simple.

namespace App\Controllers;

use Contributte\Api\Annotation\Controller\Controller;
use Contributte\Api\Annotation\Controller\Method;
use Contributte\Api\Annotation\Controller\Path;
use Contributte\Api\Annotation\Controller\RootPath;
use Contributte\Api\Http\ApiRequest;
use Contributte\Api\Http\ApiResponse;
use Contributte\Api\UI\Controller\IController;

/**
 * @Controller
 * @RootPath("/hello")
 */
final class HelloController implements IController
{

    /**
     * @Path("/world")
     * @Method("GET")
     * @param ApiRequest $request
     * @param ApiResponse $response
     * @return ApiResponse
     */
    public function index(ApiRequest $request, ApiResponse $response)
    {
        return $response->writeBody('Hello world!');
    }
}

And register your controller as service.

services:
    - App\Controllers\HelloController

As you can see, the architecture is ultra simple. ApiRequest & ApiResponse extend PSR-7, so you can re-use these declared methods.

Overview

Maintainers


Milan Felix Å ulc

The development is sponsored by Tlapnet and a lot of coffeees. Thank you guys! 👍


Thank you for testing, reporting and contributing.

  • v0.3 v0.3

    Bump! 🔪

    Diff: v0.2.2...v0.3

    Changes:

    • namespace refactoring (drop Bridges)
    • rename Factory/Generator to Serialization
    • rename Validators to Validations
    • ApiResponse/ApiRequest don't composite PSR7, they extend
    • simplify whole middlewares usage
    • simplify ApiExtension
    • added new Api2MiddlewaresExtension to easy use of middlewares
    • simplify Transformers (from 2 interfaces to 1 interface)
    • direct dependencies: contributte/psr7-http-message, contributte/middlewares, contributte/phpdoc
    • tiny micro refactorings
    • added huge amount of tests
  • v0.2.2 v0.2.2

    Bump! :goberserk:

    Diff: v0.2.1...v0.2.2

    Changes:

    • added schema validators [#1] [#2]
    • analyse via phpstan [#10]
    • added content negotiation
    • many small improvements
  • v0.2.1 v0.2.1

    Bump! 🚳

    v0.2...v0.2.1

    Changes:

    • strickness ApiRouter matching
  • v0.2 v0.2

    Bumped! 🐕

    Diff: v0.1...v0.2

    Changes:

    • rewritten ApiMiddleware (BC!)
    • introduced invokers concept:
      • ApiRouter (maps and parses request URL(s))
      • ApiContentNegotiation (converts data to any formats)
        • UrlNegotiator (negotiates content data by URL suffix)
          • JsonTransformer (encodes / decodes data)
      • ApiEmitter (passes requests to ApiDispatcher)
      • synchronize trailing slashes (at the start, at the end)
  • v0.1 v0.1

    First bump! 👊

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com