use response_output
with text/html
import { Drash } from "https://deno.land/x/drash/mod.ts";
class HomeResource extends Drash.Http.Resource {
static paths = ["/"];
public GET() {
this.response.body = "GET request received!";
if (this.request.accepts("text/html")) {
// Your HTML here
this.response.body = "<body>GET request received!</body>";
}
return this.response;
}
}
const server = new Drash.Http.Server({
response_output: "text/html",
resources: [HomeResource],
});
response_output
sets the default Content-Type
, but you can change it on a specific route by doing:
this.response.headers.set("Content-Type", "text/html");
public GET() {
this.response.headers.set("Content-Type", "application/json");
this.response.body = JSON.stringify({ foo: 'bar' });
if (this.request.accepts("text/html")) {
this.response.headers.set("Content-Type", "text/html");
this.response.body = "<body>GET request received!</body>";
}
return this.response;
}