-
Notifications
You must be signed in to change notification settings - Fork 14
Endpoint
Endpoint
is an abstraction around making REST requests. It
includes a Request
type, representing the data needed to
make the request, and a Response
type, representing the
expected response from the server.
public struct Endpoint<Request: EndpointRequest, Response: Codable>
Endpoint
s are defined via property wrapped (@GET, @POST, etc...)
properties on an EndpointGroup
.
Endpoint
s are intended to be used on either client or server for
requesting external endpoints or on server for providing and
validating endpoints. There are partner libraries
(PapyrusAlamofire
and Alchemy
) for requesting or
validating endpoints on client or server platforms.
The method, or verb, of this endpoint.
let method: EndpointMethod
The path of this endpoint, relative to self.baseURL
var path: String
The baseURL
of this endpoint.
var baseURL: String = ""
Requests a Papyrus.Endpoint
, returning a future with the
decoded Endpoint.Response
.
public func request(_ dto: Request, with client: HTTPClient = Services.client, decoder: JSONDecoder = JSONDecoder()) throws -> EventLoopFuture<(content: Response, response: HTTPClient.Response)>
- dto: An instance of the request DTO;
Endpoint.Request
. - client: The HTTPClient to request this with. Defaults to
Client.default
. - decoder: The decoder with which to decode response data to
Endpoint.Response
. Defaults toJSONDecoder()
.
An error if there is an issue encoding the request or decoding the response.
A future containing the decoded Endpoint.Response
as well as the raw response of the HTTPClient
.
Gets any information that may be needed to request this
Endpoint
.
public func parameters(dto: Request) throws -> RequestComponents
- dto: An instance of
Endpoint.Request
.
any errors that may occur when parsing out data from the Endpoint
.
A struct containing any information needed to request this endpoint with the provided instance of Request
.
Creates a copy of this Endpoint
with the provided baseURL
.
public func with(baseURL: String) -> Self
- baseURL: The baseURL for the
Endpoint
.
A copy of this Endpoint
with the baseURL
.
Request an endpoint.
public func request(_ request: Request, session: Session = .default, jsonEncoder: JSONEncoder = JSONEncoder(), jsonDecoder: JSONDecoder = JSONDecoder(), completion: @escaping (AFDataResponse<Data?>, Result<Response, Error>) -> Void) throws
- request: The request data of this endpoint.
- session: The
Alamofire.Session
with which to request this. Defaults toSession.default
. - jsonEncoder: The
JSONEncoder
to use when encoding theRequest
. Defaults toJSONEncoder()
. - jsonDecoder: The
JSONDecoder
to use when decoding theResponse
. Defaults toJSONDecoder()
. - completion: A completion that will be called when the request is complete. Contains the raw
AFDataResponse<Data>
as well as aResult
containing either the parsedResponse
or anError
.
any errors encountered while encoding the request parameters.
Generated at 2021-01-13T22:24:59-0800 using swift-doc 1.0.0-beta.5.
Alchemy
Types
- AlterTableBuilder
- BCryptDigest
- BasicAuthMiddleware
- BcryptError
- BelongsToRelationship
- CORSMiddleware
- CORSMiddleware.AllowOriginSetting
- CORSMiddleware.Configuration
- ColumnType
- CreateColumn
- CreateColumnBuilder
- CreateIndex
- CreateTableBuilder
- DatabaseConfig
- DatabaseError
- DatabaseField
- DatabaseKeyMappingStrategy
- DatabaseValue
- DayUnit
- Env
- FrequencyTyped
- Grammar
- HTTPAuth
- HTTPAuth.Basic
- HTTPAuth.Bearer
- HTTPBody
- HTTPError
- HasManyRelationship
- HasOneRelationship
- HasRelationship
- HourUnit
- JoinClause
- JoinType
- Launch
- Log
- MIMEType
- MinuteUnit
- ModelQuery
- MySQLDatabase
- Operator
- OrderClause
- OrderClause.Sort
- OrderedDictionary
- PapyrusClientError
- PathParameter
- PathParameter.DecodingError
- PostgresDatabase
- Query
- Request
- Response
- Router
- RuneError
- SQL
- SQLJSON
- Scheduler
- Schema
- SecondUnit
- Services
- Socket
- StaticFileMiddleware
- StringLength
- Thread
- TokenAuthMiddleware
- WeekUnit
- Weekday
- WhereBoolean
- WhereColumn
- WhereIn
- WhereIn.InType
- WhereNested
- WhereRaw
- WhereValue