Primate Logo Primate
Guides Responses

Serve plain text

Return strings to serve plain text responses. Primate sets Content-Type: text/plain on returned string.

Strings are served as text; use response.text() for granular control.

Return string

Primate sets Content-Type: text/plain on returned string.

TypeScriptroutes/hello.ts
import route from "primate/route";

export default route({
  get() {
    return "Hello, World!";
  },
});

Explicit text response

Use response.text() for custom options.

TypeScriptroutes/index.ts
import response from "primate/response";
import route from "primate/route";

export default route({
  get() {
    return response.text("Not found", { status: 404 });
  },
});

Custom content type

Specify MIME type.

TypeScriptroutes/index.ts
import route from "primate/route";

export default route({
  get() {
    return new Response("Custom text", {
      headers: { "Content-Type": "text/custom" },
    });
  },
});