2 ms·
I think the syntax is nicer if you take a look at the example of doing partial requests. I made this library for fun, but I'll be splitting out my requests into
by zackify 10y ago
I think the syntax is nicer if you take a look at the example of doing partial requests. I made this library for fun, but I'll be splitting out my requests into partials for an entire api. I think you get benefits from using the partials more so than your example. Either way, it was made just for fun :)
partial:
const twitter = {
register: partial`
url: https://api.twitter.com/register,
method: POST
`
}
twitter.register`
body: ${{
email: 'test@test.com',
password: 'Tester'
}}
`
Without template literals:
const twitter = {
register: {
url: 'https://api.myapp.com/register',
method: 'POST',
}
}
let response = await request({
...twitter.register,
body: body,
})
- meh321 10y agoThe second example could be more concise IMHO: const twitter = { register: function(opts){ return request({ url: '...', method: 'POST', ...opts }); } } const resp = await twitter.register({ body }); EDIT: made it even more concise! -- back to real work :/
- zackify 10y agoSure, keep adding many methods and make new functions every time. I totally get what you're saying. I just like the syntactic sugar of Template Literals :)