Skip to content

Response

Brian Zou edited this page Mar 6, 2019 · 2 revisions

Response

  • Introduction

Http response object.

  • Basic used

@Action
Response myaction1()
{
    auto user = new User;
    user.id = 9;
    user.name = "zoujiaqing";

    return new JsonResponse(user); // respond to a json object
}

@Action
Response myaction2()
{
    JSONValue j;

    // ...

    response.setJson(JSONValue j); // respond to a json object
    return response;
}

@Action
Response myaction3()
{
    return response.plain("just text"); // return string text
}

@Action
Response myaction4()
{
    return response.html("<h1>show profile </h1>"); // return html
}


@Action
Response myaction5()
{
    // chained access
    response.html("<h1>show profile </h1>")
	.setCookie("name", "value", 10000)
	.setCookie("name1", "value", 10000, "/path")
	.setCookie("name2", "value", 10000)
		.setHeader("X-Custom-Info", "hello world");

    return response;
}

For more usage, please refer to the [source/hunt/http/response.d] file under the hunt framework.

Clone this wiki locally