On Monday, August 11, 2014 10:13:41 PM UTC-4, whs860603 wrote:
I am newbie here,and try to develop a restful webservice based on the openresty module,perhaps lua-resty-http is the best one .Is there any suggestion or best practise about how to deal with the following http code in lua-resty-http or openresty?have anyone try to use the RAML or Swagger spec for the restful interface with openresty?
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 { server api.host.com:443;
keepalive 4;
}
server {
...
location /_api_proxy {
internal;
proxy_pass https://api_host;
proxy_pass_header Server;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host api.host.com;
}
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.
- Success: HTTP 200, XML/JSON representation of object (when applicable)
- Invalid: HTTP 422, XML/JSON representation of errors
- Unauthorized: HTTP 401
- Missing: HTTP 404
- Forbidden: HTTP 403
- Method not Allowed: HTTP 405
- Conflict: HTTP 409
- .....