-
-
Notifications
You must be signed in to change notification settings - Fork 129
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Describe the feature
I'd like to have the option to return raw JSON strings from route handlers, which get treated the same way on the client as if the handler returned nested structures. The idea behind this is to skip a round of JSON marshalling/unmarshalling when returning cached responses.
Currently, this is what happens if I serve a cached response:
- Cache hit
- Parse cached JSON string
- Return JSON object from the handler
- Stringify into the response body
- Parse the response body on the client
If we could return plain strings from handlers and mark them to be treated as the schema/type defined in the output() method, we could skip steps 2-4.
Potentially, the 'detailed output' structure could be updated to something like this:
os.route({
path,
method,
outputStructure: 'detailed'
})
.output(responseSchema)
.handler(() => {
const cachedResponse: string = await cache.get(key);
return {
status: 200,
preStringifiedBody: true, // <-- With this setting, the body is expected to be a string
body: cachedResponse
}
})Or a top-level route setting could be added:
os.route({
path,
method,
preStringifiedOutput: true // <-- New setting
})
.output(responseSchema)
.handler(() => {
return await cache.get(key);
})Additional information
- Would you be willing to help implement this feature?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request