0

I'd like to write a script to make REST API requests to some address. The problem is, that the address might not be accessable by everyone and also uses a token for authorization, which I wouldn't like to give away. So, my idea is to make a request to this API, trigger is a button within a webpage, but the request itself should be sent from the server itself, who's hosting the webpage, but I don't know if this is makeable.

I already wrote a sample script, which creates a request from within the browser. It works, but only for those clients, which have access granted to the server via firewall.

Expected result is that the webpage is showing from results when the script is executed.

3
  • One option is to set up nginx to attach the authorisation header and pass it on to the other API. Commented Apr 18, 2019 at 7:21
  • The other would be to just have your own API server to be receiving the request and then making the request. In any case are going to need to set up your own server, which isn't too hard. Commented Apr 18, 2019 at 7:22
  • Make the button trigger an ajax request to run a script server side which makes the request for the user and reveals nothing on the page itself. Commented Apr 18, 2019 at 7:23

1 Answer 1

3

Your clientside code should make a request to your server, which will then make a request to the API by passing the credentials, and return the response back to the client. Through that your credentials stay on the server and are not exposed.

 Client <- request -> your Server <- request + credentials -> API
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, sounds to me like using a server side script as proxy gate which executes the action sent from the client javascript code. Are there any well known resources or examples on how to build such a construct?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.