The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Calling API for internal use?

Alok Mishra's Avatar

Alok Mishra

24 Aug, 2015 03:16 PM

Hi everyone, this is a newbie question. I have the following Slim framework folder structure in my web app.

/
- api/
      Slim/
      index.php
- js/
- css/
- index.php

In api/index.php, I have methods defined like :
$app->get('/topRatedCities/:cityid/','getTopRatedCitiess');
Now typically I use the api by calling it from outside my web app (from mobile app):

http://domain.com/api/topRatedCities/4

The problem is,

I want to call the API functions from inside my web app without generating a new external HTTP request like above. When I try to do this using cURL:

http://127.0.0.1/api/topRatedCities/4

It reroutes to the domain name which is of no use for me. Is there any function from where I can directly call slimframework and the response from outside the Slim framework folder?
Since I am calling it via the domain, it is creating 100s of new requests and slowing down the website.

This is the .htaccess inside the api folder:

RewriteEngine On
RewriteBase /api

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Thanks in advance. I asked the same on SO as well:
http://stackoverflow.com/questions/32183822/call-slim-rest-endpoint-for-internal-consumption

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac