Protocols
The following protocols are available globally.
-
Requests that the
See moreService
sends to theHTTPAdapter
. This is actually just wraps theRequest
struct, erasing thePath
type so the adapter doesn’t have to deal with it.Declaration
Swift
public protocol AdapterRequest
-
The adapter for making HTTP requests. This may be implemented as an extension to a HTTP client or a custom type that implements this protocol.
It’s entirely async, with all methods receiving a callback. The adapter communicates success or failure to the callback using the
HTTPAdapterResult
enum, which encodes success and failure.All the implementation details around encoding values and generating requests is left to the adapter and underlying client.
For example, the here are some of the adapter’s responsibility:
- Authentication
- Content negotiation
- Caching
Declaration
Swift
public protocol HTTPAdapter
-
Defines the base requirements for types that interact with Yopuy.
Note: This protocol should not be used directly, instead use the
See moreRootResource
,ChildResource
,SingularRootResource
orSingularChildResource
protocols.Declaration
Swift
public protocol Resource
-
Defines a resource which is identifiable. That is, it has an
id
property and instances can be retrieved from the remote API by ID. This also implies that the resource is listable. So it includes the requirement for theparse(collection:)
function.Note: Do not use this protocol directly. You should instead conform your resources to
See moreRootResource
orChildResource
Declaration
Swift
public protocol IdentifiableResource: Resource
-
Defines a resource that exists at the root of the remote API.
Declaration
Swift
public protocol RootResource: Resource, IdentifiableResource
-
Defines a resource that is a child of another.
Note: This protocol should not be used directly, instead use the
ChildResource
andSingularChildResource
protocols.Declaration
Swift
public protocol NestedResource: Resource
-
Defines a resource that is related to a parent resource, which may be a
RootResource
or anotherChildResource
. This is done via theassociatedtype Parent
declaration. This is used as a constraint in order to direct the type-safe construction of paths which are used for requests.Declaration
Swift
public protocol ChildResource: NestedResource, IdentifiableResource
-
Defines a resource which exists at the root of the remote API and which has only one instance. Rather than being addressed by an ID, it is addressed by a constant path.
Declaration
Swift
public protocol SingularRootResource: Resource
-
Defines a resource that is related to a parent resource, which may be a
RootResource
or anotherChildResource
and has only one instance. Rather than being addressed by an ID, it is addressed by a constant path.The relationship to the parent is done via the
associatedtype Parent
declaration. This is used as a constraint in order to direct the type-safe construction of paths which are used for requests.Declaration
Swift
public protocol SingularChildResource: NestedResource
-
Flags a resource as being listable i.e. it has a collection. This protocol does nothing by itself, but has constrained extensions for types implementing
See moreRootResource
andChildResource
.Declaration
Swift
public protocol IsListable: Resource
-
Flags a resource as being showable i.e. a single resource can be requested. This protocol does nothing by itself, but has constrained extensions for types implementing
See moreRootResource
andChildResource
.Declaration
Swift
public protocol IsShowable: Resource
-
Flags a resource as being deletable. This protocol does nothing by itself, but has constrained extensions for types implementing
See moreRootResource
andChildResource
.Declaration
Swift
public protocol IsDeletable: Resource
-
Flags a resource as being creatable. This protocol does nothing by itself, but has constrained extensions for types implementing
See moreRootResource
andChildResource
.Declaration
Swift
public protocol IsCreatable
-
Flags a resource as being replacable i.e. supports
See morePUT
. This protocol does nothing by itself, but has constrained extensions for types implementingRootResource
andChildResource
.Declaration
Swift
public protocol IsReplaceable
-
Flags a resource as being patchable i.e. supports
See morePATCH
. This protocol does nothing by itself, but has constrained extensions for types implementingRootResource
andChildResource
.Declaration
Swift
public protocol IsPatchable
-
A convenience protocol which allows a resource to opt into all of the
Is*
protocols. It will add:Declaration
Swift
public protocol IsRESTFul: IsListable, IsCreatable, IsShowable, IsReplaceable, IsPatchable, IsDeletable