RestOperations

Handles REST services' operations.

Implements: IConfigurable, IReferenceable

Description

The RestOperations class allows you to handle REST services' operations.

Constructors

Create instance of rest operations

RestOperations()

Creates rest operations with name

RestOperations.withName(String name)

  • name: String - component name

Fields

logger

Composite logger component

logger: CompositeLogger = CompositeLogger()

counters

Counter component

counters: CompositeCounters = CompositeCounters()

dependencyResolver

Dependency resolver component

dependencyResolver: DependencyResolver = DependencyResolver()

Instance methods

configure

Configures a component by passing its configuration parameters.

@override void configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

getTraceId

Returns a traceId from a request

String? getTraceId(shelf.Request req)

  • req: shelf.Request - an HTTP request
  • returns: String? - traceId from a request

getFilterParams

Gets the filter parameters.

FilterParams getFilterParams(shelf.Request req)

  • req: shelf.Request - an HTTP request
  • returns: FilterParams - filter paramters

getPagingParams

Gets the paging parameters.

PagingParams getPagingParams(shelf.Request req)

  • req: shelf.Request - an HTTP request
  • returns: PagingParams - paging paramters

invoke

Invokes an operation.

Function(shelf.Request req) invoke(String operation)

  • operation: String - operation to be invoked
  • returns: Function(shelf.Request req) - operation

instrument

Adds instrumentation to log calls and measures call time. It returns a CounterTiming object that is used to end the time measurement.

CounterTiming instrument(IContext context, String name)

  • context: IContext - (optional) a context to trace execution through a call chain.
  • name: String - method name.
  • returns: CounterTiming - object to end the time measurement.

sendBadRequest

Sends a bad request error message.

FutureOr<shelf.Response> sendBadRequest(shelf.Request req, String message)

  • req: any - HTTP request
  • message: String - message
  • returns: FutureOr<shelf.Response> - HTTP response

sendConflict

Sends a conflict error messge

FutureOr<shelf.Response> sendBadRequest(shelf.Request req, String message)

  • req: shelf.Request - HTTP request context
  • message: String - message
  • returns: FutureOr<shelf.Response> - HTTP response

sendCreatedResult

Sends a JSON object with the created result.

FutureOr<shelf.Response> sendCreatedResult(shelf.Request req, err, result)

  • req: shelf.Request - HTTP request context
  • err: dynamic - error to be sent.
  • result: dynamic - result to be sent.
  • returns: FutureOr<shelf.Response> - HTTP response context

sendDeletedResult

Sends the deleted result in JSON format.

FutureOr<shelf.Response> sendDeletedResult(shelf.Request req, err, result)

  • req: shelf.Request - HTTP request context
  • err: dynamic - error to be sent.
  • result: dynamic - result to be sent.
  • returns: FutureOr<shelf.Response> - HTTP response context

sendEmptyResult

Send an empty result with 204 status code.

FutureOr<shelf.Response> sendEmptyResult(shelf.Request req, err)

  • req: shelf.Request - HTTP request context
  • err: dynamic - error to be sent.
  • returns: FutureOr<shelf.Response> - HTTP response context

sendError

Sends an error serialized as ErrorDescription object and appropriate HTTP status code.

FutureOr<shelf.Response> sendError(shelf.Request req, error)

  • req: shelf.Request - HTTP request context
  • err: dynamic - error to be sent.
  • returns: FutureOr<shelf.Response> - HTTP response context

sendInternalError

Sends an internal error message

FutureOr<shelf.Response> sendInternalError(shelf.Request req,, String message)

  • req: shelf.Request - HTTP request context
  • message: String - message
  • returns: FutureOr<shelf.Response> - HTTP response context

sendNotFound

Sends a not found error message.

FutureOr<shelf.Response> sendNotFound(shelf.Request req, String message)

  • req: shelf.Request - HTTP request context
  • message: String - message
  • returns: FutureOr<shelf.Response> - HTTP response context

sendResult

Sends a result as a JSON object.

FutureOr<shelf.Response> sendResult(shelf.Request req, err, result)

  • req: shelf.Request - HTTP request context
  • err: dynamic - error to be sent.
  • result: dynamic - result to be sent.
  • returns: FutureOr<shelf.Response> - HTTP response context

sendServerUnavailable

Sends a server unavailable error message (Status code 503).

FutureOr<shelf.Response> sendServerUnavailable(shelf.Request req,, String message)

  • req: shelf.Request - HTTP request context
  • message: String - message
  • returns: FutureOr<shelf.Response> - HTTP response context

sendSessionExpired

Sends a session expired error message (Status code 440).

FutureOr<shelf.Response> sendSessionExpired(shelf.Request req,, String message)

  • req: shelf.Request - HTTP request context
  • message: String - message
  • returns: FutureOr<shelf.Response> - HTTP response context

sendUnauthorized

Sends an unauthorized error message.

FutureOr<shelf.Response> sendUnauthorized(shelf.Request req, String message)

  • req: shelf.Request - HTTP request context
  • message: String - message
  • returns: FutureOr<shelf.Response> - HTTP response context

setReferences

Sets the specified references.

@override

void setReferences(IReferences references)