how to request external REST API ?

1,145 views
Skip to first unread message

Payne Chu

unread,
Sep 24, 2013, 10:52:40 AM9/24/13
to openre...@googlegroups.com
Hi, ngx.location.capture seems just use for internal sub-request. But any function can do https request to external API specifically for REST?

Payne Chu

unread,
Sep 24, 2013, 11:18:16 AM9/24/13
to openre...@googlegroups.com

Payne Chu

unread,
Sep 24, 2013, 11:52:37 AM9/24/13
to openre...@googlegroups.com
orz... seems no solution for https yet -> https://github.com/chaoslawful/lua-nginx-module/issues/178

Payne Chu

unread,
Sep 24, 2013, 12:01:47 PM9/24/13
to openre...@googlegroups.com
can ngx.location.catpure + proxy_pass to solve https issue ?

Yichun Zhang (agentzh)

unread,
Sep 24, 2013, 3:43:57 PM9/24/13
to openresty-en
Hello!

On Tue, Sep 24, 2013 at 9:01 AM, Payne Chu wrote:
> can ngx.location.catpure + proxy_pass to solve https issue ?
>

Yes, of course. The standard ngx_proxy module always supports https anyway.

Regards,
-agentzh

Payne Chu

unread,
Sep 24, 2013, 9:37:39 PM9/24/13
to openre...@googlegroups.com
Thanks Agentzh,

Do you have any lua sample to show how ngx.location.capture + proxy_pass work?

I only find https://github.com/leafo/heroku-openresty/wiki/Making-HTTP-Requests the moon script version.

it use $_uri to pass to proxy_pass. will it have any race condition issue?

Yichun Zhang (agentzh)

unread,
Sep 24, 2013, 10:41:57 PM9/24/13
to openresty-en
Hello!

On Tue, Sep 24, 2013 at 6:37 PM, Payne Chu wrote:
> Thanks Agentzh,
>

Don't capitalize my nick please.

> Do you have any lua sample to show how ngx.location.capture + proxy_pass
> work?
>

Just configure a location with ngx_proxy, and in another location,
initiate a subrequest via the ngx.location.capture().

You can find a lot of examples in ngx_lua's (declarative) test suite,
especially in the following test file:

https://github.com/chaoslawful/lua-nginx-module/blob/master/t/020-subrequest.t#L25

>
> it use $_uri to pass to proxy_pass. will it have any race condition issue?
>

Every Nginx request has its own Nginx variable copy. No race condition
is possible here. You can check out my Nginx tutorials (still under
work!) here for more details:

http://openresty.org/download/agentzh-nginx-tutorials-en.html

You can also find a lot of simple code examples there.

Best regards,
-agentzh

Payne Chu

unread,
Sep 24, 2013, 10:48:15 PM9/24/13
to openre...@googlegroups.com
haa thanks agentzh :D~
Reply all
Reply to author
Forward
0 new messages