CreatedResource

This is meant to be returned by a function that takes a form POST submission. You want to set the url of the new resource it created, which is set as the http Location header for a "201 Created" result, and you can also set a separate destination for browser users, which it sets via a "Refresh" header.

The resourceRepresentation should generally be the thing you just created, and it will be the body of the http response when formatted through the presenter. The exact thing is up to you - it could just return an id, or the whole object, or perhaps a partial object.

version(with_breaking_cgi_features)
struct CreatedResource (
T
) {
static if(!is(T == void))
T resourceRepresentation;
string resourceUrl;
string refreshUrl;
}

Examples

class Test : WebObject {
	@(Cgi.RequestMethod.POST)
	CreatedResource!int makeThing(string value) {
		return CreatedResource!int(value.to!int, "/resources/id");
	}
}

Meta

History

Added December 18, 2021