diff --git a/README.md b/README.md
index f099fb6..aa8c142 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ Provides HTMX integration for ASP.NET Core applications.
* [HtmxRequestAttribute](#htmxrequestattribute)
* [HttpResponse](#httpresponse)
* [The declarative way of setting response headers](#the-declarative-way-of-setting-response-headers)
- * [TagHelpers](#taghelpers)
+ * [Tag Helpers](#tag-helpers)
* [HtmxUrlTagHelper](#htmxurltaghelper)
* [HtmxHeaderTagHelper](#htmxheadertaghelper)
* [HtmxValsTagHelper](#htmxvalstaghelper)
@@ -26,8 +26,8 @@ Provides HTMX integration for ASP.NET Core applications.
## Getting Started
-Install `Ramstack.HtmxToolkit` [NuGet package](https://www.nuget.org/packages/Ramstack.HtmxToolkit/) to your project,
-use the following command
+Add the [`Ramstack.HtmxToolkit` NuGet package](https://www.nuget.org/packages/Ramstack.HtmxToolkit/)
+to your project with the following command:
```console
dotnet add package Ramstack.HtmxToolkit
@@ -56,8 +56,7 @@ builder.Services.AddHtmxToolkit();
## HttpRequest
-The library provides a set of classes for working with `HttpRequest`.
-First off, there's the `HttpRequestExtensions` class.
+The library provides the `HttpRequestExtensions` class for working with `HttpRequest`.
```csharp
///
@@ -66,22 +65,23 @@ First off, there's the `HttpRequestExtensions` class.
public static class HttpRequestExtensions
{
///
- /// Determines whether the specified HTTP request is htmx request.
+ /// Determines whether the specified HTTP request is an HTMX request.
///
/// The HTTP request.
///
- /// true if the specified HTTP request is htmx request; otherwise, false.
+ /// if the specified HTTP request is an HTMX request;
+ /// otherwise, .
///
public static bool IsHtmxRequest(this HttpRequest request);
///
- /// Determines whether the specified HTTP request is htmx request.
+ /// Determines whether the specified HTTP request is an HTMX request.
///
/// The HTTP request.
- /// When this methods returns, contains the
- /// that provides well-known htmx headers.
+ /// When this method returns, contains the
+ /// that provides access to well-known HTMX headers.
///
- /// true if the specified HTTP request is htmx request; otherwise, false.
+ /// if the specified HTTP request is an HTMX request; otherwise, .
///
public static bool IsHtmxRequest(this HttpRequest request, out HtmxRequestHeaders headers);
@@ -91,7 +91,7 @@ public static class HttpRequestExtensions
///
/// The HTTP request.
///
- /// true if the specified HTTP request is boosted; otherwise, false.
+ /// if the specified HTTP request is boosted; otherwise, .
///
public static bool IsHtmxBoosted(this HttpRequest request);
@@ -100,31 +100,31 @@ public static class HttpRequestExtensions
/// instead of a normal navigation.
///
/// The HTTP request.
- /// When this methods returns, contains the
- /// that provides well-known htmx headers.
+ /// When this method returns, contains the
+ /// that provides access to well-known HTMX headers.
///
- /// true if the specified HTTP request is boosted; otherwise, false.
+ /// if the specified HTTP request is boosted; otherwise, .
///
public static bool IsHtmxBoosted(this HttpRequest request, out HtmxRequestHeaders headers);
///
- /// Returns the that provides well-known htmx headers.
+ /// Returns a strongly typed view of the HTMX request headers.
///
/// The HTTP request.
///
- /// The .
+ /// The .
///
public static HtmxRequestHeaders GetHtmxHeaders(this HttpRequest request);
}
```
-The `IsHtmxRequest` method allows you to determine whether the current request is initiated by HTMX.
+Use `IsHtmxRequest` to determine whether the current request was issued by HTMX.
```csharp
HttpContext.Request.IsHtmxRequest()
```
-And thus, you can define different scenarios depending on the result, for example:
+You can then handle HTMX and regular requests differently, for example:
```csharp
if (Request.IsHtmxRequest())
@@ -133,7 +133,7 @@ if (Request.IsHtmxRequest())
return View();
```
-The overloads of these methods provide access to strongly typed headers set by HTMX:
+The overloads with an `out` parameter also provide access to strongly typed headers set by HTMX:
```csharp
if (Request.IsHtmxRequest(out var headers))
@@ -145,13 +145,13 @@ if (Request.IsHtmxRequest(out var headers))
}
```
-In addition, access to strongly typed headers can be obtained by calling `GetHtmxHeaders`:
+You can also access strongly typed headers by calling `GetHtmxHeaders`:
```csharp
var headers = Request.GetHtmxHeaders();
```
-The full list of headers is presented below:
+The complete set of request header properties is shown below:
```csharp
///
@@ -160,8 +160,7 @@ The full list of headers is presented below:
public readonly struct HtmxRequestHeaders
{
///
- /// Gets a value indicating whether the request
- /// was made using AJAX instead of a normal navigation.
+ /// Gets a value indicating whether the request was made using AJAX instead of a normal navigation.
///
public bool Boosted { get; }
@@ -171,57 +170,56 @@ public readonly struct HtmxRequestHeaders
public string? CurrentUrl { get; }
///
- /// Gets a value indicating whether the request
- /// is for history restoration after a miss in the local history cache.
+ /// Gets a value indicating whether the request restores history after a miss in the local history cache.
///
public bool HistoryRestoreRequest { get; }
///
- /// Gets the user response to an hx-prompt on the client.
+ /// Gets the user's response to an hx-prompt on the client.
///
public string? Prompt { get; }
///
- /// Gets a value indicating whether the current request is htmx request.
+ /// Gets a value indicating whether the current request is an HTMX request.
///
public bool Request { get; }
///
- /// Gets the ID of the target element if it exists.
+ /// Gets the ID of the target element, if present.
///
public string? Target { get; }
///
- /// Gets the name of the triggered element if it exists.
+ /// Gets the name of the triggered element, if present.
///
public string? TriggerName { get; }
///
- /// Gets the ID of the triggered element if it exists
- /// as indicated by the HX-Trigger header.
+ /// Gets the ID of the triggered element, if present.
///
public string? Trigger { get; }
}
```
-Example of usage:
+For example:
```csharp
-if (Request.GetHtmxHeaders().HistoryRestoreRequests)
+if (Request.GetHtmxHeaders().HistoryRestoreRequest)
{
...
}
```
-The library also provides a set of predefined string constants for request headers,
-so you don't have to remember them each time and risk making mistakes in spelling.
-You can find them in the `HtmxRequestHeaderNames` class.
+The `HtmxRequestHeaderNames` class also provides constants for well-known request header names,
+so you do not have to remember their exact spelling.
```csharp
///
-/// Defines constants for the well-known names of htmx request headers.
-/// For more information, see https://htmx.org/reference/#request_headers
+/// Defines constants for the well-known names of HTMX request headers.
///
+///
+/// For more information, see HTMX Request Headers Reference.
+///
public static class HtmxRequestHeaderNames
{
///
@@ -242,11 +240,11 @@ public static class HtmxRequestHeaderNames
### HtmxRequestAttribute
-To simplify some manual checks, the library provides an ASP.NET Core result filter
-that can be applied to an action controller, page handler, or the entire controller:
+To route HTMX requests to a specific controller action, apply the `HtmxRequestAttribute`
+action constraint to that action:
```csharp
-public class UserController : ControlleBase
+public class UserController : ControllerBase
{
[HtmxRequest]
public IActionResult UpdateProfile(UserProfile profile)
@@ -256,10 +254,10 @@ public class UserController : ControlleBase
}
```
-If you are processing boosted requests in a special way, add the `Boosted` parameter.
+To match only boosted requests, set the `Boosted` property to `true`:
```csharp
-public class UserController : ControlleBase
+public class UserController : ControllerBase
{
...
[HtmxRequest(Boosted = true)]
@@ -272,8 +270,7 @@ public class UserController : ControlleBase
## HttpResponse
-For working with response headers, the library also provides a set of classes.
-The first one is the `HttpResponseExtension` class with extension methods:
+For working with response headers, the library provides the `HttpResponseExtensions` class:
```csharp
///
@@ -282,27 +279,28 @@ The first one is the `HttpResponseExtension` class with extension methods:
public static class HttpResponseExtensions
{
///
- /// Returns the that provides well-known htmx headers.
+ /// Returns a strongly typed view of the HTMX response headers.
///
/// The HTTP response.
///
- /// The .
+ /// The .
///
public static HtmxResponseHeaders GetHtmxHeaders(this HttpResponse response);
///
- /// Configures the htmx response headers.
+ /// Configures the HTMX response headers.
///
/// The HTTP response to configure.
- /// The function to configure the htmx response headers.
+ /// The delegate that configures the HTMX response headers.
public static void Htmx(this HttpResponse response, Action configure);
///
- /// Configures the htmx response headers.
+ /// Configures the HTMX response headers.
///
/// The HTTP response to configure.
- /// The function to configure the htmx response headers.
- /// The value to pass to the .
+ /// The delegate that configures the HTMX response headers
+ /// using .
+ /// The state passed to .
public static void Htmx(this HttpResponse response, Action configure, TState state);
}
```
@@ -317,14 +315,15 @@ that control HTMX behavior.
public readonly struct HtmxResponseHeaders
{
///
- /// Gets or sets the HX-Location header to a client-side redirect
- /// that does not do a full page reload.
+ /// Gets or sets the value of the HX-Location header, which performs
+ /// a client-side redirect without a full-page reload.
///
[MaybeNull]
public string Location { get; set; }
///
- /// Gets or sets the HX-Push-Url header to push a new URL into the history stack.
+ /// Gets or sets the value of the HX-Push-Url header, which pushes a new URL
+ /// onto the browser's history stack.
///
[MaybeNull]
public string PushUrl { get; set; }
@@ -334,29 +333,30 @@ public readonly struct HtmxResponseHeaders
}
```
-Just like `HtmxRequestHeaderNames`, which consists of predefined string constants for HTMX request headers,
-there is a corresponding `HtmxResponseHeaderNames` class containing
-a list of string constants for HTMX response headers.
+Just as `HtmxRequestHeaderNames` defines constants for HTMX request headers,
+`HtmxResponseHeaderNames` defines constants for HTMX response headers.
```csharp
///
-/// Defines constants for the well-known names of htmx response headers.
-/// For more information, see https://htmx.org/reference/#response_headers
+/// Defines constants for the well-known names of HTMX response headers.
///
+///
+/// For more information, see HTMX Response Headers Reference.
+///
public static class HtmxResponseHeaderNames
{
///
- /// The HX-Location header is used to a client-side redirect that does not do a full page reload.
+ /// The HX-Location header performs a client-side redirect without a full-page reload.
///
public const string Location = "HX-Location";
///
- /// The HX-Push-Url header is used to push a new URL into the history stack.
+ /// The HX-Push-Url header pushes a new URL onto the browser's history stack.
///
public const string PushUrl = "HX-Push-Url";
///
- /// The HX-Redirect header is used to client-side redirect to a new location.
+ /// The HX-Redirect header performs a client-side redirect to a new location.
///
public const string Redirect = "HX-Redirect";
@@ -365,9 +365,8 @@ public static class HtmxResponseHeaderNames
}
```
-However, the most convenient and efficient way is by using one of the provided `Htmx` methods
-with a callback that accepts `HtmxResponse`, allowing you to specify response headers
-in a fluent style:
+The most convenient approach is to use one of the `Htmx` extension methods.
+Its callback receives an `HtmxResponse`, allowing you to configure response headers in a fluent style:
```csharp
Response.Htmx(h => h
@@ -377,7 +376,7 @@ Response.Htmx(h => h
.StopPolling(ShouldStopPolling));
```
-:bulb: The second Htmx method accepts an additional parameter to avoid unnecessary allocations due to closures:
+:bulb: The generic overload accepts an additional state parameter to avoid closure allocations:
```csharp
Response.Htmx(
@@ -395,17 +394,16 @@ Response.Htmx(
return Json(profile).Htmx(h => h.StopPolling(ShouldStopPolling));
```
-In both cases, the headers will be set only in the case of an `htmx` request.
-In the case of a regular request, the callback passed to the `Htmx(this)` method will not be executed,
-which allows avoiding unnecessary work.
+In all these examples, headers are set only for an HTMX request. For a regular request,
+the callback passed to `Htmx` is not executed, avoiding unnecessary work.
### The declarative way of setting response headers
-Some of the response headers can be set declaratively using the `HtmxResponseAttribute`,
-which is applied to the controller, action, or page.
+Some response headers can be set declaratively by applying `HtmxResponseAttribute`
+to a controller or action:
```csharp
-public class UserController : ControlleBase
+public class UserController : ControllerBase
{
[HtmxRequest]
[HtmxResponse(
@@ -418,18 +416,18 @@ public class UserController : ControlleBase
}
```
-:bulb: If a more complex expression is needed for `swap`, for example, `innerHTML show:#result:top`,
-you can use the `Reswap` method in the `HtmxResponse` class, which accepts a string.
+:bulb: For a more complex swap expression, such as `innerHTML show:#result:top`,
+use the `Reswap` overload that accepts a string.
```csharp
///
/// Sets the HX-Reswap header to specify how the response will be swapped.
///
-/// The header value to set.
+/// The swap style to assign to the header.
///
/// The current instance.
///
-public HtmxResponse Reswap(string value);
+public HtmxResponse Reswap(HtmxSwap value);
///
/// Sets the HX-Reswap header to specify how the response will be swapped.
@@ -438,50 +436,58 @@ public HtmxResponse Reswap(string value);
///
/// The current instance.
///
-public HtmxResponse Reswap(HtmxSwap value);
+public HtmxResponse Reswap(string value);
```
-And for the `HtmxResponseAttribute`, there is the `ReswapExpression` property.
+For declarative configuration, `HtmxResponseAttribute` provides the `ReswapExpression` property:
```csharp
///
-/// Gets or sets the HX-Reswap header that allows to specify how the response will be swapped.
+/// Gets or sets the complete HX-Reswap header value, including any swap modifiers.
///
[MaybeNull]
public string ReswapExpression { get; set; }
///
-/// Gets or sets the HX-Reswap header that allows to specify how the response will be swapped.
+/// Gets or sets the swap style to specify in the HX-Reswap header.
///
public HtmxSwap Reswap { get; set; }
```
-allowing you to flexibly configure the `swap` header you need.
+Use `ReswapExpression` when the strongly typed `Reswap` property is not flexible enough.
-## TagHelpers
+## Tag Helpers
-The library provides 4 tag helpers:
+The library provides five tag helpers:
* `HtmxUrlTagHelper`
* `HtmxHeaderTagHelper`
-* `HtmxConfigTagHelper`
+* `HtmxValsTagHelper`
* `HtmxRequestTagHelper`
+* `HtmxConfigTagHelper`
-To make them available in your project, add the `@addTagHelper` directive in the Razor view.
+To make them available in your project, add the `@addTagHelper` directive to a Razor view:
```razor
@addTagHelper *, Ramstack.HtmxToolkit
```
-To make the tag helpers available globally for the entire application, you should add this line
-to the `_ViewImports.cshtml` file, which is inherited by all view files by default.
+To make the tag helpers available throughout the application, add this line to
+`_ViewImports.cshtml`, which is inherited by Razor views by default.
+
+Import the toolkit namespace there as well if a view refers to toolkit types:
+
+```razor
+@using Ramstack.HtmxToolkit
+```
### HtmxUrlTagHelper
-The `HtmxUrlTagHelper` allows generating links for HTMX methods similar to how it's done in ASP.NET Core
-for generating links, just replace the `asp-` prefix with the `hx-` prefix.
+The `HtmxUrlTagHelper` generates URLs for HTMX requests in much the same way that
+the built-in ASP.NET Core tag helpers generate links. In most cases, replace the `asp-` prefix
+with `hx-`:
-```html
+```razor