Support Plain Text Request
Closed this issue · 2 comments
We should support this:
let response = await request`
url: https://api.myapp.com/register
method: POST
headers: {"Authorization":"Bearer: token"}
body: {"email":"test@test.com","password":"secret"}
`
Why? Because documenting an api could be done this way, which would allow end users to copy and paste the exact string and run the request. Does it sound cool?
I think this would be covered by #10. I envision a check being done on the body value and being able to handle multiple different formats, including an already-stringified/plain text value.
Something else to consider would be this scenario:
let response = await request`
url: https://api.myapp.com/register
method: POST
headers: {"Authorization":"Bearer: token"}
body: {"email":${email},"password":${password}}
`
The parser right now can't replace multiple values on the same line. It could be refactored to do so. Still, if a user is going to pass an object to the body with dynamic values, it would be best to make the whole object a variable, like so:
let response = await request`
url: https://api.myapp.com/register
method: POST
headers: {"Authorization":"Bearer: token"}
body: ${{
email: email,
password: password
}}
`
Do you think it's worth creating another ticket to allow for multiple variables to be passed per line? I can envision the following scenario: url: ${host}/${endpoint}
If you want to sure, I would be okay with telling people they have to use one variable per line, ex ${``${host}/${endpoint}``}
but more flexible, the better. ignore the double backtick. idk how to escape them lol