Expose a REST API¶
Publish an HTTP or HTTPS endpoint that accepts requests, runs your integration logic and returns a structured response.
Choose a host component¶
| HttpHost | WebServiceHost | APIHost | |
|---|---|---|---|
| Exposes | HTTP/HTTPS endpoints | SOAP web services (.asmx) |
REST endpoints with named routes |
| Request handling | The request flows to the next component on the canvas | Each web method writes to an MSMQ request queue and waits on a response queue | Optional C# pre-processing, then an MSMQ request queue |
| Best for | Simple endpoints handled within one interface | SOAP callers that need typed methods and classes | High-throughput REST APIs processed by background workers |
| Reference | This page | This page | APIHost |
Build an endpoint with HttpHost¶
- Add the host
Drag HttpHost onto the canvas, set itsEndPointtoSource, and set:Prefixes: one or more listening addresses, for examplehttps://+:8443/api/orders/ValidIpAddresses: the client addresses allowed to connectUpdateMessageStore:Trueto put the request parameters in the Message Store - Validate the request
Link the host to a Csharp component that checks the payload and stores the values you need. - Do the work
Link to SqlProcedure, SqlQuery or a client component such as RESTfulService or WebService. - Return the response
Set the last component'sEndPointtoServer. Its result travels back along the chain as the reply to the caller. Components such as SqlProcedure can return errors on the reply path withReturnErrorandErrorPrefix. - Secure it
Use HTTPS and bind a certificate to the port. See Security.
Host a SOAP web service with WebServiceHost¶
WebServiceHost publishes an .asmx service whose methods hand requests to message queues, so other interfaces process them.
| Property | Purpose |
|---|---|
Prefixes, Virtual Path, Name |
Where the service listens. A prefix of http://+:8000/ serves http://server:8000/<Name>.asmx. |
Physical Path |
Folder for the generated .asmx and web.config files |
Namespace |
The service namespace, for example http://tempuri.org/ |
Additional Classes |
Custom types, each with a class name and typed properties (optionally arrays) |
WebServices |
One entry per web method: Name, typed Arguments, ReturnType, RequestQueue, ResponseQueue and TimeOut |
AutoGenerateCall, PreCallCode, PostCallCode |
Optional C# that shapes the request, or turns the queue reply (answer) into the return type |
Response format¶
Use a consistent response contract so callers can handle every outcome the same way. i-Con doesn't impose a format, but this pattern for delimited responses works well and is used on many i-Con projects:
| Outcome | Format |
|---|---|
| Success | R00\|<Status>\|<ReferenceNo>\|<Payload> |
| Failure | R01\|<ErrorMessage>\|<ReferenceNo>\|<ErrorCode> |
For JSON APIs, return an object with status, message, timestamp and data fields. The APIHost has an example.
Keep request handling fast
If the work takes longer than about 2.5 seconds, queue it, return a reference straight away and notify the caller when it finishes. See Asynchronous queue processing.