{"id":15176388,"url":"https://github.com/kingluo/lua-resty-ffi-req","last_synced_at":"2025-10-26T11:31:26.702Z","repository":{"id":185026109,"uuid":"623776184","full_name":"kingluo/lua-resty-ffi-req","owner":"kingluo","description":"The openresty http client library, supports http1, http2 and http3","archived":false,"fork":false,"pushed_at":"2023-04-05T11:33:30.000Z","size":19,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-31T18:56:51.341Z","etag":null,"topics":["coroutines","http-client","http2-client","http3-client","lua","luajit","nginx","openresty"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kingluo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-05T04:09:49.000Z","updated_at":"2024-07-04T20:09:31.000Z","dependencies_parsed_at":"2023-07-31T12:49:48.361Z","dependency_job_id":null,"html_url":"https://github.com/kingluo/lua-resty-ffi-req","commit_stats":null,"previous_names":["kingluo/lua-resty-ffi-req"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingluo%2Flua-resty-ffi-req","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingluo%2Flua-resty-ffi-req/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingluo%2Flua-resty-ffi-req/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingluo%2Flua-resty-ffi-req/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kingluo","download_url":"https://codeload.github.com/kingluo/lua-resty-ffi-req/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238319474,"owners_count":19452343,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coroutines","http-client","http2-client","http3-client","lua","luajit","nginx","openresty"],"created_at":"2024-09-27T13:03:53.866Z","updated_at":"2025-10-26T11:31:26.373Z","avatar_url":"https://github.com/kingluo.png","language":"Go","readme":"# lua-resty-ffi-req\n\nThe openresty http client library, supports http1, http2 and http3.\n\nIt encapsulates golang [req](https://req.cool/) library.\n\n## Background\n\nCheck this blog for more detail:\n\nhttp://luajit.io/posts/http3-client-for-openresty\n\nHTTP2/HTTP3 protocol is popular now,\nbut OpenResty does not support them.\n\n[req](https://req.cool/) is an intresesing golang library, which provides an unique API\nfor all HTTP versions.\n\nHighlights:\n\n* automatically detect the server side and select the optimal HTTP version for requests, you can also force the protocol if you want\n* Easy Download and Upload (form-data, file)\n\nWhy not encapsulate it so that we could reuse it in openresty?\n\n[lua-resty-ffi](https://github.com/kingluo/lua-resty-ffi) provides an efficient and generic API to do hybrid programming\nin openresty with mainstream languages (Go, Python, Java, Rust, Nodejs).\n\n`lua-resty-ffi-req = lua-resty-ffi + req`\n\n## Synopsis\n\n```lua\nlocal req = require(\"resty.ffi.req\")\nlocal client, err = req:new_client()\nlocal ok, res = client:request{\n    url = \"http://httpbin.org/anything?foo=bar\",\n    body = \"hello\",\n    args = {\n        foo1 = \"foo1\",\n        foo2 = 2,\n        foo3 = false,\n        foo4 = 2.2,\n    },\n}\nassert(ok)\nngx.say(inspect(res))\nngx.say(inspect(cjson.decode(res.body)))\n\nlocal ok, res = client:request{\n    method = req.HTTP_POST,\n    url = \"http://httpbin.org/anything\",\n    body = coroutine.wrap(function()\n        coroutine.yield(\"hello\")\n    end),\n    body_reader = true,\n}\nassert(ok)\nngx.say(inspect(res))\n\nlocal body = {}\nfor chunk in res.body_reader do\n    table.insert(body, chunk)\nend\nngx.say(inspect(cjson.decode(table.concat(body, \"\"))))\n```\n\n## Demo\n\n```bash\n# install lua-resty-ffi\n# https://github.com/kingluo/lua-resty-ffi#install-lua-resty-ffi-via-luarocks\n# set `OR_SRC` to your openresty source path\nluarocks config variables.OR_SRC /tmp/tmp.Z2UhJbO1Si/openresty-1.21.4.1\nluarocks install lua-resty-ffi\n\ncd /opt\ngit clone https://github.com/kingluo/lua-resty-ffi-req\ncd /opt/lua-resty-ffi-req\nmake\n\ncd /opt/lua-resty-ffi-req/demo\n\n# run nginx\nLD_LIBRARY_PATH=/opt/lua-resty-ffi-req:/usr/local/lib/lua/5.1 \\\nnginx -p $PWD -c nginx.conf\n\n# in another terminal, run demo\ncurl localhost:20000/demo/get\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingluo%2Flua-resty-ffi-req","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkingluo%2Flua-resty-ffi-req","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingluo%2Flua-resty-ffi-req/lists"}