request method
Creates a configured HTTP request for a service endpoint.
This method creates an HTTP request object that is pre-configured with the correct base URL, authentication context, and access token handling. You can then use the returned request object to make GET, POST, PUT, DELETE, or other HTTP requests.
Parameters
route: The service route to request (defaults to '/')
Returns
An HttpRequest object ready for making HTTP calls
Examples
// GET request
final response = await calljmp.service
.request(route: '/api/users')
.get()
.json((json) => json);
// POST request
final created = await calljmp.service
.request(route: '/api/posts')
.post({
'title': 'My Post',
'content': 'Post content here',
})
.json((json) => json);
// PUT request with custom headers
final updated = await calljmp.service
.request(route: '/api/posts/123')
.header('Content-Type', 'application/json')
.put({'title': 'Updated Title'})
.json((json) => json);
// DELETE request
await calljmp.service
.request(route: '/api/posts/123')
.delete();
Implementation
http.HttpRequest request({String route = '/'}) {
final sanitizedRoute = route.replaceFirst(RegExp(r'^/'), '');
return http
.request('$url/$sanitizedRoute')
.use(http.context(_config))
.use(http.access());
}