0

I've been tasked with making a RESTful api, pretty simple, just serving up a couple of tables. You should be able to lookup countries by either business or consumer, or get info by country or state, for example. The problem is, the syntax requires that an api call should look like:

<domain>/api/v1/Business.Country

or like

<domain>/api/v1/Consumer.Country/us

or

<domain>/api/v1/Consumer.Country/us/State

Is this even possible with that dot in there? This is on a LAMP platform, so I guess it could be done with some kind of fancy Rewrite, but I wonder how flexible that could be for future expansion of the api.

mutatron
  • 563
  • 3
  • 7
  • 19

1 Answers1

0

Yes it is very much possible (and valid) to have dot in your URIs. You can write some .htaccess based mod_rewrite rules to route these requests appropriately.

Sample Rewrite Rules:

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# to handle cases like <domain>/api/v1/Business.Country/us
RewriteRule ^api/v1/Business\.[^/]+/(.*?)/?$ /business?country=$1 [L,QSA,NC]

# to handle cases like <domain>/api/v1/Consumer.Country/us
RewriteRule ^api/v1/Consumer\.[^/]+/(.*?)/?$ /consumer?country=$1 [L,QSA,NC]
Community
  • 1
  • 1
anubhava
  • 761,203
  • 64
  • 569
  • 643