Introducing PSX: A PHP framework to build APIs based on RAML specifications


#1

Hi, I like to introduce PSX. PSX is a framework written in PHP which helps
to build RESTful APIs. Basically it can read RAML files and generate an
API endpoint which behaves like the specification.

It validates all query and path parameters. Also it reads the JsonSchema of
the request/response and validates incoming requests accordingly. Outgoing
data is also formatted so that the API is always in sync with the specification.
More informations about the project at the website http://phpsx.org/ or on
GitHub at https://github.com/k42b3/psx.


#2

Hi,
I’m interesting in some tools like PSX. I read quickly the documentation and some code, it seems a good project. I have a question about an architectural choice.

The project uses external modules (logging, dependency injection,…).
But some other concepts like Request, Response, etc… are re-defined. Is there an advantage to use this approach compared to build on a micro-framework (like Silex for example) ?
The same question about the Raml parser : why don’t use alecsammon’s parser ?

Thanks for your work !


#3

Hi Yves, thx for the feedback! To your first question I think it is more a
design preference. With micro-frameworks you have to register the routes and
callbacks in PHP which can be confusing if you have a lot of routes or complex
callbacks. In PSX you have a routes file (i.e. https://github.com/k42b3/psx-sample/blob/v1.1.1/routes)
which contains all routes to callback mappings. Both approaches have pros and
cons but I think for PSX it works really well.

Regarding the RAML parser, PSX has an extra layer between the specification
format and the validation process. The RAML parser in PSX produces only a bunch
of objects which represent the specification. Theoretical it would be possible
to write another parser which creates theses objects from another API
specification format. PSX works then with these objects to i.e. validate
incoming request data. Because of that the library is not the best solution for
PSX. So I hope this answers your questions.