URLs building for the API's
If you find yourself in this case:
const API_URL = 'https://api.example.com/';
function getUserPosts(id, blogId, limit, offset) {
const requestUrl = `${API_URL}/users/${id}/blogs/${blogId}/posts?limit=${limit}&offset=${offset}`;
// send HTTP request
}
like writing a clumsy URL, then you might be interested in getting here:
const API_URL = 'https://api.example.com/';
function getUserPosts(id, limit, offset) {
const requestUrl = urlcat(API_URL, '/users/:id/posts', { id, limit, offset });
// send HTTP request
}
I have migrated to this urlcat library, and indeed my ajax req code seems airier.
Check it out, it might help you too.
cheers,