effect-http
effect-http copied to clipboard
Content-Type header seems to be fixed to application/json
Hello, I want to set content-type header to text/plain in a response to a get request. I tried your example but without Schema.struct it does not compile. The code below compiles but the response has still application/json. Could you please tell me how to set content-type header correctly?
import {Effect} from "effect";
import {NodeServer} from "effect-http";
import {PrettyLogger} from "effect-log";
import {RouterBuilder} from "effect-http";
import {Api} from "effect-http";
import * as Schema from "@effect/schema/Schema";
export const api = Api.api({title: "Example API"}).pipe(
Api.get("root", "/", {
response: {
status: 200,
content: Schema.string,
headers: Schema.struct({"Content-Type": Schema.string}),
},
}),
);
export const app = RouterBuilder.make(api).pipe(
RouterBuilder.handle("root", () =>
Effect.succeed({
content: "Hello World!",
status: 200 as const,
headers: {"content-type": "text/plain"},
}),
),
RouterBuilder.build,
)
const program = app.pipe(
NodeServer.listen({port: 3000}),
Effect.provide(PrettyLogger.layer()),
);
Effect.runPromise(program);
{
"dependencies": {
"@effect/schema": "^0.48.3",
"effect": "2.0.0-next.55",
"effect-http": "^0.39.0",
"effect-log": "^0.23.1"
},
"devDependencies": {
"prettier": "^3.1.0",
"tsx": "^4.1.3",
"typescript": "^5.2.2"
}
}