IPWorks IoT 2020 Delphi Edition

Questions / Feedback?

Request Event

Fires when a request is received from a client.

Syntax

type TRequestEvent = procedure (
  Sender: TObject;
  const RemoteHost: String;
  RemotePort: Integer;
  Method: Integer;
  const URIHost: String;
  URIPort: Integer;
  const URIPath: String;
  const URIQuery: String;
  Token: String;
  TokenB: TBytes;
  const RequestId: String;
  var SendResponse: Boolean
) of Object;

property OnRequest: TRequestEvent read FOnRequest write FOnRequest;

Remarks

This event fires anytime a request is received from a client. Information about the request is exposed both via this event's parameters and the following properties: RequestData, RequestContentFormat, RequestETag, and RequestOption*.

A response can either be sent back to the client immediately when the event finishes, or later using the SendResponse method. Refer to the RequestId and SendResponse parameters' documentation, below, for more information. If a response is to be sent back immediately, populate the ResponseCode, ResponseData, ResponseContentFormat, ResponseETag, and ResponseOption* properties as desired before this event finishes.

The RemoteHost parameter reflects the client's IP address or hostname.

The RemotePort parameter reflects the client's port.

The Method parameter reflects the request method code. The following table provides a (non-exhaustive) list of some of the more common method codes; refer to the IANA's CoAP Method Codes registry for a full list.

Method Code Name
1 GET
2 POST
3 PUT
4 DELETE
5 FETCH
6 PATCH

The URIHost, URIPort, URIPath, and URIQuery parameters, when taken together, identify the resource that the client is making a request against. This event exposes the URI in pieces for convenience.

The Token parameter reflects the token included in the request.

The RequestId parameter reflects the component-generated Id for the request. If the final value of the SendResponse parameter is False, this Id can be passed to the SendResponse method later to send a response. (Alternatively, it can be passed to the CancelRequest later to ignore the request.)

The SendResponse parameter specifies whether the component should send a response back to the client immediately; it is True by default. Set it to False to send the response later instead.

Note: This event is only used when the component is operating in server mode (i.e., when the Listening property is enabled).

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks IoT 2020 Delphi Edition - Version 20.0 [Build 8265]