Multiplatform Ktor schema declaration • opensavvy.spine.api • DynamicResource
DynamicResource¶
A resource with a wildcard segment: v1/users/{user}, v1/posts/{post}/subscribers/{user}.
To declare a resource of this type, create a singleton:
// URL: v1
object Api : RootResource("v1") {
// URL: v1/users
object Users : StaticResource<Api>("users", parent = Api) {
// Endpoint: GET v1/users
val list by get()
.response<List<UserDto>>()
// URL: v1/users/{user}
object User : DynamicResource<Users>("user", parent = Users) {
// Endpoint: GET v1/users/{user}
val get by get()
.response<UserDto>()
}
}
}
Parameters¶
- Parent
-
The type of the direct parent of this resource. Because of restrictions of the Kotlin language, it must be specified explicitly even if it already appears in the line because it is passed to parent.
See also¶
AnyEndpoint.BuilderDeclaring endpoints in a resource.
Constructors¶
DynamicResource¶
Creates a new DynamicResource. The passed slug should be a single word, which is the name of the wildcard added to the parent's URL: for example, "user" or "id". When such a resource is imported into Ktor, it recognizes that it is a wildcard. The exact value can be accessed on the server using the idOf function.
Types¶
Identified¶
class Identified<Parent : Resource, Self : DynamicResource<Parent>>
Holder for a DynamicResource and a specific slug that matches its declared wildcard.
Properties¶
children¶
Returns resources that are direct children of the current resource.
directEndpoints¶
Returns all endpoints that are declared on this resource.
endpoints¶
val Resource.endpoints: Sequence<AnyEndpoint>
Returns all endpoints that are declared on this resource or any of its children.
fullSlug¶
The complete URL of this resource, starting from the RootResource, to this resource.
hierarchy¶
Returns the hierarchy of this resource: following the parent chain.
parent¶
The parent resource of this resource.
slug¶
The URL segment relating to this specific resource.