This PR adds support for generating Datastar fetch expressions directly from ZIO HTTP Endpoint definitions. Instead of manually writing Datastar request strings, developers can now automatically generate them from their endpoint definitions.
When using Datastar with ZIO HTTP endpoints, developers had to manually construct Datastar fetch expressions like @get('/api/users'). This was error-prone and didn’t leverage the type-safe endpoint definitions we already have. This PR bridges that gap.
EndpointRequest - New trait representing a Datastar request action with method, URL, headers, and optionsEndpointRequestBuilder - Builder class for constructing requests from endpoints with fluent APItoDatastarRequest to Endpoint for easy conversiondataFetch shortcuts in Attributes trait for quick request creationdata-on attributesimport zio.http._
import zio.http.endpoint._
// Define an endpoint
val endpoint = Endpoint(RoutePattern.GET / "api" / "users")
// Generate Datastar request - simple!
val request = endpoint.toDatastarRequest.build()
// Result: @get('/api/users')
// With path parameters
val userEndpoint = Endpoint(RoutePattern.GET / "api" / "users" / PathCodec.int("id"))
val userRequest = userEndpoint.toDatastarRequest.build(42)
// Result: @get('/api/users/42')
// With signals for dynamic values
val deleteRequest = userEndpoint.toDatastarRequest.buildWithSignals()
// Result: @get('/api/users/${id}')
// Using the shorthand helper
val fetchRequest = dataFetch.get("/api/users")
Closes #3697
Ali Raza
@aliraza556
ZIO
@ZIO