Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get request.body array #21

Open
maryigoshyna opened this issue Jul 23, 2018 · 3 comments
Open

Cannot get request.body array #21

maryigoshyna opened this issue Jul 23, 2018 · 3 comments

Comments

@maryigoshyna
Copy link

maryigoshyna commented Jul 23, 2018

Hello!
I have next problem.
I have such body in request: "body": "ignore_ip=1&data%5Bcomments_allowed_for%5D=0" . And I need to use second value in it (data[comments_allowed_for]) , but it's possible to get only first value ignore_ip.
How can I get other values except first? By documentation I can see next https://github.com/jmartin82/mmock/blob/master/config/body-form.json.
So I try to do next:
"{{ request.body.data[comments_allowed_for] }}"
"{{ request.body.data }}"
"{{ request.body.data.comments_allowed_for }}"
e.t.
But even when I do request using regex , for ex {{request.body.(?P\w+)}} , I get only first parameter ignore_ip .
So please tell me please what I should do to resolve my problem

@vtrifonov
Copy link
Owner

Hi @maryigoshyna are you using jmartin82's mmock repo or my fork, as it is older than the original one. My fork does not support request.body.data, so your only option is to use regex.

@maryigoshyna
Copy link
Author

@vtrifonov , I use your http-api-mock.
But as I wrote in previous message, I try to use regex, but I get only first parameter . And Cannot get data (array) . Is it possible ? Maybe you can show me some examples

@vtrifonov
Copy link
Owner

vtrifonov commented Jul 27, 2018

Thats because you are matching only letters with (?P\w+), if you want to get the value of comments_allowed_for you should use something like {{request.body..*comments_allowed_for.*=(?P<value>\\d+)}}. You need to add the regex that matches the value that you want from the body after request.body. including a named group value which will be the result from the match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants