Skip to content
Snippets Groups Projects
Commit dc147ec9 authored by Sergey Bronnikov's avatar Sergey Bronnikov Committed by Igor Munkin
Browse files

httpc: implement encoding params

@TarantoolBot document
Title: Document encoding parameters in http client

New option "params" passed to HTTP request allows a user to add query
parameters into URI. When option "params" contains a Lua table with
key-value pairs these parameters encoded to a string and passed as an
URL path in GET/HEAD/DELETE methods and as a HTTP body with POST method.
In a latter case error will be raised when body is not empty.

```
> uri = require("uri")
> httpc = require("httpc")
> params = { key1 = 'value1', key2 = uri.values('value1', 'value2') }
> r = http.client.get("http://httpbin.org/get", { params = params })
> r.url
---
- http://httpbin.org/get?key1=value1&key2=value1&key2=value2
...

```

Key and values could be a Lua number, string, boolean, anything that has
a `__serialize` or `__tostring` metamethod. It is possible to pass
datetime, decimal and number64 values.

Limitations:

- order of keys with values in a result string is not deterministic
- percent encoding is not supported at the moment

Closes #6832
parent ffe7408c
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment