Much like freshie/router -> navaid, re-export httpie as freshie/request or freshie/http -- no changes.
Benefit is that it'll include a universal HTTP client regardless of the SSR choice. The resolve.mainFields are already configured correctly to enable this.
Finally, if you don't use freshie/request, it won't be included at all. There are no internal assumptions made about what/how you're preloading. Opt-in usage would look like this:
import { send } from 'freshie/request';
export async function preload(req, context) {
let res = await send('GET', '...', ...);
return { ... }
}
Another benefit to this is that because httpie throws (normalized) errors on 4xx responses, you don't have to deal with preload errors by default~! Your 4xx or xxx error template will automatically step in and send the correct error output. However, if you don't want this, you just handle the error manually, as you normally would (and can't avoid in other frameworks) anyway:
import { send } from 'freshie/request';
export async function preload(req, context) {
try {
let res = await send('GET', '...', '...');
return { success: true };
} catch (err) {
// send different props to current view
// instead of deferring to Error page output
return { success: false };
}
}
Much like
freshie/router
->navaid
, re-exporthttpie
asfreshie/request
orfreshie/http
-- no changes.Benefit is that it'll include a universal HTTP client regardless of the SSR choice. The
resolve.mainFields
are already configured correctly to enable this.Finally, if you don't use
freshie/request
, it won't be included at all. There are no internal assumptions made about what/how you're preloading. Opt-in usage would look like this:Another benefit to this is that because
httpie
throws (normalized) errors on 4xx responses, you don't have to deal with preload errors by default~! Your4xx
orxxx
error template will automatically step in and send the correct error output. However, if you don't want this, you just handle the error manually, as you normally would (and can't avoid in other frameworks) anyway: