How to add headers in rest api other than onBefore Request ?

Hi Team, 

we are trying to find a common place to make a generic function to add headers to rest api calls ,

We have explored onbefore request, but our auth-token is stored in local storage in a blank module and 

we can't figure out how to pass local storage data from blank module to a service module.


Please help us resolving this query ASAP. 

mvp_badge
MVP

Hi Aditya,


As I see it, you have two ways:

1. Your REST API is called synchronously from your app - you can have the header as a parameter of the REST API and fill it with the value you want, like on the image below:


2. Your REST API is called asynchronously - in that case, you will have to store the value in the database and fill it on the OnBeforeRequest or in a parameter as in the image above. When you run the REST API asynchronously, there is no way the server side can obtain information from the client side, so saving it in the database is the way to do so, in order to have access to the data when consuming the REST API on the server side.


Kind Regards,
João

is there any way to have a database specific to a particular app and not stored in the outsystem's server .

Champion

Hi,
Although Joao had already mentioned an approach; but here's something that I would like to highlight:

  • You told the auth key resides on the blank module.
  • You can either keep the auth key on Site property or local storage as per your requirement & create a public action/function which returns the same
  • Now you just need to call the action created in OnBeforerequest & override the AuthHey Heder Value on the Rest Collection in Service Studio.
  • In this way you can easily address the issue [ considering it's on web :) ]

Hope it helps;

Assif

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.