AssetService

com.alecdorrington.assetloader.tapir.AssetService
class AssetService[F[_]](externalPath: EndpointInput[Unit], internalPath: Path, maxAge: Int = ...) extends AssetApi, TapirService[Any, F]

A Tapir service for serving static assets loaded by an AssetLoader.

Type parameters

F

The effect type (e.g. Future or IO).

Value parameters

externalPath

The URL path prefix for the endpoint, e.g. "assets".

internalPath

The root directory on the server's file system where assets are stored, relative to the directory of the running server process, e.g. "src/main/resources".

maxAge

The maximum age (in seconds) for which an asset should be considered fresh for caching purposes. Caching is disabled by default (0).

Attributes

Graph
Supertypes
trait TapirService[Any, F]
class AssetApi
class Object
trait Matchable
class Any

Members list

Type members

Inherited types

final type Endpoint = ServerEndpoint[Any, F]

The upper bound on the type of all API endpoints in this service.

The upper bound on the type of all API endpoints in this service.

Attributes

Inherited from:
TapirService

Value members

Concrete methods

final override def api: List[Endpoint]

A list of all endpoints implemented in this service.

A list of all endpoints implemented in this service.

Attributes

Definition Classes

The server implementation for publicEndpoint.

The server implementation for publicEndpoint.

Attributes

Example

Minimal example with Netty and Cats Effect:

 object Main extends ResourceApp.Forever:
   val assets = AssetService[IO](
     "assets",
     Paths.get("src/main/resources"),
   )
   def run(args: List[String]) =
     NettyCatsServer
       .io()
       .flatMap: server =>
         val service = server
           .host("0.0.0.0")
           .port("8080")
           .addEndpoints(assets.serverEndpoint)
         Resource.make(service.start())(_.stop()).as(())

Inherited methods

def publicEndpoint: PublicEndpoint[(List[String], Option[String]), StatusCode, (Array[Byte], String, String, String), Any]

The definition for a Tapir endpoint that serves static files.

The definition for a Tapir endpoint that serves static files.

Attributes

See also

AssetService.serverEndpoint for the server implementation.

Inherited from:
AssetApi

Inherited fields

lazy val all: List[Endpoint]

All endpoints combined from api, docs, and metrics.

All endpoints combined from api, docs, and metrics.

Attributes

Inherited from:
TapirService
lazy val docs: List[Endpoint]

Swagger documentation for this service.

Swagger documentation for this service.

Attributes

Inherited from:
TapirService
lazy val metrics: List[Endpoint]

Prometheus metrics for this service.

Prometheus metrics for this service.

Attributes

Inherited from:
TapirService