apioo / psx

PSX is an innovative PHP framework dedicated to build fully typed REST APIs.
https://phpsx.org
Apache License 2.0
170 stars 13 forks source link

Consider use of JAX-RS annotations to provide meta informations for an controller #3

Closed chriskapp closed 8 years ago

chriskapp commented 9 years ago

Java has already some common annotations to declare which HTTP methods and paths are available for an API endpoint (http://docs.oracle.com/cd/E19798-01/821-1841/giepu/index.html). We could use these annotations in an controller to provide meta informations how an controller/method can be used. We could probably add an discover command which parses all controllers from the source and vendor folder and suggest how you can add them to your routing file. Probably we could also extract an description about the controller. In this way users could easily add new controllers to their application and since they must manually add the route there is no risk that malicious packages register unwanted routes. The annotations could look like:

class FooController extends ControllerAbstract
{
    /**
     * @GET
     * @POST
     * @Path('/foo/:id')
     * @Consumes("application/json")
     * @Produces("application/json")
     */
    public function doIndex()
    {
    }
}
chriskapp commented 8 years ago

Implemented in version 1.2