This document outlines every public method on FortitudeResponse, examples assume you are inside a handler and already have a FortitudeResponse res instance.
Gets or sets the originating request ID.
res.RequestId = requestId;Gets or sets the HTTP-like status code.
res.Status = 404;Gets or sets the response content type.
res.ContentType = "application/json";Gets or sets the response headers dictionary.
res.Headers["X-Test"] = "value";Gets or sets the raw response body.
res.Body = Encoding.UTF8.GetBytes("hello");Indicates whether the status code is in the 2xx range.
if (res.IsSuccessStatusCode) { }Converts the response into an HttpResponseMessage.
var httpResponse = res.ToHttpResponseMessage();Sets a 200 OK plain-text response.
res.Ok("Success");Sets a 200 OK JSON response.
res.Ok(new { message = "Success" });Sets a 201 Created JSON response and optional Location header.
res.Created(new { id = 1 }, "/items/1");Sets a 202 Accepted response.
res.Accepted();Sets a 204 No Content response and clears the body.
res.NoContent();Sets a 400 Bad Request response.
res.BadRequest("Invalid input");Sets a 401 Unauthorized response.
res.Unauthorized();Sets a 403 Forbidden response.
res.Forbidden();Sets a 404 Not Found response.
res.NotFound();Sets a 409 Conflict response.
res.Conflict("Already exists");Sets a 429 Too Many Requests response with optional Retry-After header.
res.TooManyRequests("Slow down", 30);Sets a 500 Internal Server Error response.
res.InternalServerError();Sets a 501 Not Implemented response.
res.MethodNotImplemented();Sets a 504 Gateway Timeout response.
res.GatewayTimeout();Sets a 302 Found redirect response.
res.Redirect("/login");Sets a 308 Permanent Redirect response.
res.PermanentRedirect("/new-endpoint");Sets a 304 Not Modified response and clears the body.
res.NotModified("abc123");Sets a plain-text response with the specified status code.
res.SetText(418, "I'm a teapot");Sets the response body to UTF-8 encoded plain text.
res.SetTextBody("Hello world");Sets a JSON response with the specified status code.
res.SetJson(200, new { ok = true });Sets a binary response body.
res.SetBinary(fileBytes, "application/pdf");Sets a file download response.
res.File(fileBytes, "report.pdf", "application/pdf");Clears the response body.
res.ClearBody();Adds or removes a response header.
res.WithHeader("X-Test", "value");Adds or replaces multiple response headers.
res.WithHeaders(new Dictionary<string,string> { ["X-A"] = "1" });Removes all response headers.
res.ClearHeaders();Sets the Location header.
res.WithLocation("/items/1");Sets the ETag header.
res.WithETag("abc123");Sets the Cache-Control header.
res.WithCacheControl("public, max-age=60");Disables client and intermediary caching.
res.WithNoCache();Sets the X-Correlation-Id header.
res.WithCorrelationId(correlationId);Sets the Retry-After header.
res.WithRetryAfter(30);