Request parses POST data contains array arg "improperly"?

Could you guys help me with this?

When I make post request which contains an array arg:

curl --location --request POST 'http://127.0.0.1:8080/push' \
  --form 'names[0]="name0"' \
  --form 'names[1]="name1"' \
  --form 'names[2]="name2"'

The request.form is as below:

I thought the request.form should be like this:

{
    'names': ['name0', 'name1', 'name2']
}

Thanks!

To stack them in an array, the correct format would be:

curl --location --request POST 'http://127.0.0.1:8080/push' \
  --form 'names="name0"' \
  --form 'names="name1"' \
  --form 'names="name2"'

Then you would get:

{'names': ['name0', 'name1', 'name2']}

You can see it in the docs here: Request | Sanic Framework

Maybe it could be more explicit that the same applies to form data.

Thanks for the reply.

Actually I make the request in a PHP backend.
Generally, the request would be like this:

$client = new Client([
    'baseUrl' => 'http://127.0.0.1:8080',
]);

$client->post('/push', [
    'names' => [
        'name0',
        'name1',
        'name2',
    ]
]);

This Client make a request equivalent to a curl command execution:

curl --location --request POST 'http://127.0.0.1:8080/push' \
  --form 'names[0]="name0"' \
  --form 'names[1]="name1"' \
  --form 'names[2]="name2"'

That’s why I post this question.

Maybe I can change the names to ‘name0,name1,name2’, or see if this Client can make a request like this:

curl --location --request POST 'http://127.0.0.1:8080/push' \
  --form 'names="name0"' \
  --form 'names="name1"' \
  --form 'names="name2"'

Thanks again!