You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
682 B
25 lines
682 B
import ResponseFactory from './ResponseFactory.ts'
|
|
import {Request} from '../Request.ts'
|
|
|
|
/**
|
|
* Response factory that writes the given value as JSON.
|
|
* @extends ResponseFactory
|
|
*/
|
|
export default class JSONResponseFactory extends ResponseFactory {
|
|
constructor(
|
|
/**
|
|
* The value to be JSON serialized and written.
|
|
*/
|
|
public readonly value: any
|
|
) {
|
|
super()
|
|
}
|
|
|
|
public async write(request: Request): Promise<Request> {
|
|
request = await super.write(request)
|
|
request.response.headers.set('Content-Type', 'application/json')
|
|
request.response.body = JSON.stringify(this.value)
|
|
return request
|
|
}
|
|
}
|