-3

I have an API in my app, how can I call the API in a JS script when I don't have a URL and I'm still in development?

Heraclitus
  • 80
  • 11

1 Answers1

2

Do not specify the domain name as part of the API's URL and deploy the JavaScript application to the same domain/port as the PHP API. You may have to do this anyway for security reasons (look up CORS).

So, if you call your API endpoint at /api/endpoint from your application deployed at /app, you will be independent of the domain, no matter if you are working locally

http://localhost:8080/app
http://localhost:8080/api/endpoint

, or in production

https://example.com/app
https://example.com/api/endpoint
TimoStaudinger
  • 41,396
  • 16
  • 88
  • 94
  • I had tried this but I didn't get it working, I think I didn't put the http:// for some reason. Stupid of me. Cheers mate – Heraclitus Jan 30 '17 at 21:45