lua-resty-http is an HTTP client. Are you trying to consume a RESTful web service?
You can create an internal location which proxies to an upstream server (including HTTPS hosts).
For example:
http {
...
upstream api_host { keepalive 4;
}
server {
...
location /_api_proxy {
internal;
proxy_pass_header Server;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
location / {
content_by_lua '
local res = ngx.location.capture("/_api_proxy")
...
';
}
}
}
If you're trying to create a RESTful web service then you have a lot of choices.
For creating a dynamic response body you might look at
content_by_lua. The
cjson module is especially useful for serializing to JSON text and it is already included in the OpenResty bundle.
You can easily set the correct status using
ngx.status (also see
HTTP status constants).
If you can tell us a bit more about your requirements we might be able to offer more assistance.