pub struct Mounted<'a> {
pub schema: &'a ResourceSchema,
pub base_path: &'a str,
}domain only.Expand description
A resource schema paired with the path it is served under.
The base path is not a domain concept — the domain does not know it is being served over HTTP — so the router supplies it alongside the schema.
Fields§
§schema: &'a ResourceSchema§base_path: &'a strImplementations§
Source§impl<'a> Mounted<'a>
impl<'a> Mounted<'a>
pub fn new(schema: &'a ResourceSchema, base_path: &'a str) -> Self
Sourcepub fn record(&self, id: &str) -> Record<'_, Self>
pub fn record(&self, id: &str) -> Record<'_, Self>
Start a resource object for id, in one step.
Mounted::new(&schema, "/api/v1/todos")
.record("t_1")
.attr("message", "buy milk")
.rel("owner", "u_01H8X")
.build()
```ignoreSourcepub fn record_from(&self, record: &DomainRecord) -> Record<'_, Self>
pub fn record_from(&self, record: &DomainRecord) -> Record<'_, Self>
Serialize an ash_domain::Record straight from the domain.
Two things are dropped from attributes, because JSON:API carries
them elsewhere: the primary key, which becomes the envelope id, and
every relationship’s source attribute — a foreign key belongs in
linkage, not beside the data. Everything else is converted as-is.
Relationships are added afterwards, since a Record holds foreign
keys rather than linkage:
mounted.record_from(&record).rel("owner", owner_id).build()Source§impl<'a> Mounted<'a>
impl<'a> Mounted<'a>
Sourcepub fn parse_create<R>(
&self,
document: &Value,
ctx: &Context,
) -> Result<R, JsonApiError>
pub fn parse_create<R>( &self, document: &Value, ctx: &Context, ) -> Result<R, JsonApiError>
Read a create document into the resource’s own type.
The document is expected to have passed
DocumentValidator already —
shape, required members and linkage are its job. What remains here is
the typed conversion, driven by the schema’s declared attribute types.
Sourcepub fn parse_update<R>(
&self,
document: &Value,
id: &str,
ctx: &Context,
) -> Result<R, JsonApiError>
pub fn parse_update<R>( &self, document: &Value, id: &str, ctx: &Context, ) -> Result<R, JsonApiError>
Read an update document into the resource’s own type.
Same as Mounted::parse_create, except the primary key comes from
the URL: a PATCH addresses a row that already exists, and the id in
the path is authoritative over anything the body says.
Source§impl Mounted<'_>
impl Mounted<'_>
Sourcepub fn record_for_create(
&self,
document: &Value,
ctx: &Context,
) -> Result<DomainRecord, JsonApiError>
pub fn record_for_create( &self, document: &Value, ctx: &Context, ) -> Result<DomainRecord, JsonApiError>
A create document as a domain Record.
The document has already passed the validator, so what is left is the typed conversion the schema drives.
Sourcepub fn record_for_update(
&self,
document: &Value,
id: &str,
ctx: &Context,
) -> Result<DomainRecord, JsonApiError>
pub fn record_for_update( &self, document: &Value, id: &str, ctx: &Context, ) -> Result<DomainRecord, JsonApiError>
An update document as a domain
Record, with the path’s id.
A PATCH addresses a row that exists, so the URL’s id wins over
anything the body carries.