MCPcopy Create free account
hub / github.com/Effect-TS/effect / json

Function json

packages/effect/src/http/HttpServerResponse.ts:310–323  ·  view source on GitHub ↗
(
  body: unknown,
  options?: Options.WithContentType | undefined
)

Source from the content-addressed store, hash-verified

308 * @since 4.0.0
309 */
310export const json = (
311 body: unknown,
312 options?: Options.WithContentType | undefined
313): Effect.Effect<HttpServerResponse, Body.HttpBodyError> => {
314 const headers = options?.headers ? Headers.fromInput(options.headers) : Headers.empty
315 return Effect.map(Body.json(body, getContentType(options, headers)), (body) =>
316 makeResponse({
317 status: options?.status ?? 200,
318 statusText: options?.statusText,
319 headers,
320 cookies: options?.cookies,
321 body
322 }))
323}
324
325/**
326 * Creates a JSON response constructor backed by a schema encoder.

Callers

nothing calls this directly

Calls 4

getContentTypeFunction · 0.85
makeResponseFunction · 0.70
mapMethod · 0.45
jsonMethod · 0.45

Tested by

no test coverage detected