Hi All I am trying to create one mock api, in whic...
# general
p
Hi All I am trying to create one mock api, in which the value of query parameter should be passed to the "each" loop's array - for example, if some one trying the create send an url as /hello/friends?friends=5, this number 5 should be passed in the each block in the response as {{#each (array 1 2 3 4 5)}} I tried the following created the urlPattern as "urlPattern": "/hello/friends\\?friends=5", and response as {{#each (range 1 ( request.query.friends))}}{{this}} - can some one help me over here to fix what I am missing
l
The tricky thing here is to force the query param to an integer so you can use it with the
range
helper. There might be a better way to do this but off the top of my head, the
math
helper seems to work -
math request.query.friends '+' 0
You can then use it with the
each
and `range`:
Copy code
{ [
{{#each (range 1 (math request.query.friends '+' 0)) as |friend|}}
{{friend}},
{{/each}}
] }
With a request like this -
/friends?friends=5
you should get this:
Copy code
{ [
1,
2,
3,
4,
5,
] }
p
Thanks a lot @Lee Turner!! it worked like charm
🙌 1