Skip to content

Commit

Permalink
Improving http docs a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Sep 7, 2023
1 parent caad991 commit f20ad87
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
6 changes: 0 additions & 6 deletions docs/guide/http/endpoints.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# HTTP Endpoints

::: warning
In all cases, the resource returned from a Wolverine HTTP endpoint method **is not automatically
published as a Wolverine cascaded message**. At this moment you will have to directly use `IMessageBus`
in your method signature to publish messages.
:::

First, a little terminology about Wolverine HTTP endpoints. Consider the following endpoint method:

<!-- snippet: sample_simple_wolverine_http_endpoint -->
Expand Down
7 changes: 7 additions & 0 deletions docs/guide/http/sagas.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ public static (
<sup><a href='https://github.com/JasperFx/wolverine/blob/main/src/Http/WolverineWebApi/SagaExample.cs#L14-L32' title='Snippet source file'>snippet source</a> | <a href='#snippet-sample_starting_saga_from_http_endpoint' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

Remember in Wolverine.HTTP that the *first* return value of an endpoint is assumed to be the response body by Wolverine, so if you are
wanting to start a new saga from an HTTP endpoint, the `Saga` return value either has to be a secondary value in a tuple to
opt into the Saga mechanics. Alternatively, if all you want to do is start a new saga, but nothing else, you can return
the `Saga` type *and* force Wolverine to use the return value as a new `Saga` like so:

snippet: sample_start_saga_from_http_endpoint_empty_body

2 changes: 1 addition & 1 deletion src/Http/Wolverine.Http/NotBodyAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Wolverine.Http;
/// Wolverine that this parameter is *not* sourced from the
/// HTTP request body
/// </summary>
[AttributeUsage(AttributeTargets.Parameter)]
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
public class NotBodyAttribute : Attribute
{
}
16 changes: 16 additions & 0 deletions src/Http/WolverineWebApi/SagaExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ public static (
}

#endregion

#region sample_start_saga_from_http_endpoint_empty_body

[WolverinePost("/reservation2")]

// This directs Wolverine to disregard the Reservation return value
// as the response body, and allow Wolverine to use the Reservation
// return as a new saga
[EmptyResponse]
public static Reservation Post2(StartReservation start)
{
return new Reservation { Id = start.ReservationId };
}

#endregion

}

public record BookReservation(string Id);
Expand Down

0 comments on commit f20ad87

Please sign in to comment.