NJS - API Calls

Dmitry Volyntsev xeioex at nginx.com
Mon Jun 3 18:03:13 UTC 2019



On 03.06.2019 20:43, naidile.pn wrote:
> 
> I want to make a REST API call which is on a different server to fetch a 
> property.
> 
> And add the property to the request from client and proxy it


Currently you can do it using two sublocations with proxy_pass 
directives 
(http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass).

--------------------
function js_content(r) {

r.subrequest("/property", reply => {

    if (reply.status != 200)  { r.return(500, "prop failed"); return; }

    r.subrequest('/backend', res => {
      ...
    })
  })
}

------------------

We plan to add a Promise object this year, so in the future it will be 
less cumbersome.


More information about the nginx-devel mailing list