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

Function json

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

Source from the content-addressed store, hash-verified

288 * @since 4.0.0
289 */
290export const json = (
291 body: unknown,
292 options?: Options.WithContentType | undefined
293): Effect.Effect<HttpServerResponse, Body.HttpBodyError> => {
294 const headers = options?.headers ? Headers.fromInput(options.headers) : Headers.empty
295 return Effect.map(Body.json(body, getContentType(options, headers)), (body) =>
296 makeResponse({
297 status: options?.status ?? 200,
298 statusText: options?.statusText,
299 headers,
300 cookies: options?.cookies,
301 body
302 }))
303}
304
305/**
306 * 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