Using Slim in REST Microservice Architecture

Marius

22 Oct, 2014 03:49 PM

Hi,

I'm trying to use Slim as a Platform for some REST
microservices. The concept is really simple, you separate a big
service into smaller ones. However I have encountered a problem
with mod_rewrite and routing on Apache, which I can't solve.
(RewriteBase /approot - not working either)

/approot contains .htaccess Each RewriteRule is a path to a
microservice.

Apache Root is in /htdocs
Application Root containing the single page application
(index.html) is in /htdocs/approot

The api script for the first microservice is located in:
/htdocs/approot/api/v1/area.php
The area.php contains routes starting with
/area.
Every time I try to access the http://localhost/approot/area
I get 404 Error from Slim.

I have read some solutions in this forum and tried for a few
hours to get this to work, trying different routes and different
rewrite options and traces (httpd.conf : LogLevel alert
rewrite:trace3). At least, I could verify that rewrite does what it
should.

So far, the only possibility to make it work is to put area.php
as api_area.php into /htdocs/approot, which
basically eliminates the idea of api versioning.

Is it possible to provide a solutioin to this dilemma other than
to make /approot apache server root directory?

Slim has code to chop off the extra routes, but if it doesn't match the request with the actual folder being ran in, then it doesn't remove that extra routing and requires you to either add the base route to all the routes, or you can implement this little hack I put in which allows you to specify the base route.