RTC Forums

Subscription => Support => Topic started by: ClementDoss on November 14, 2015, 09:23:21 PM



Title: REST server example
Post by: ClementDoss on November 14, 2015, 09:23:21 PM
Hi,

Do you have an example (or guidelines) to build a REST server using RTC?
I would like to build a server given the client might not be using RTC.

TIA,
Clément


Title: Re: REST server example
Post by: D.Tkalcec (RTC) on November 16, 2015, 08:49:09 AM
There are no REST-specific examples in the RTC SDK, but ... if you know how to use the RTC SDK to build a Server (which is already covered in Quick Start examples) and you understand the protocol, you should be able to do it with the RTC SDK. You have full access to all the data you get with Client requests and you have full control when preparing your responses, so it's all about processing that request data to prepare the appropriate response. If you are new to REST and want to learn the protocol, you can start by googling "REST guidelines".

Best Regards,
Danijel Tkalcec


Title: Re: REST server example
Post by: ClementDoss on November 17, 2015, 04:59:49 PM
Hi Danijel,

I'm familiar with the REST protocol. I want to be sure I'm not reinventing the wheel  ;)

For example, rtcserver will receive a GET like: http://www.acme.com/product/0

I don't know how to accept this request. How should I inform rtcServer that http://www.acme.com/product is the actual link, and that 0 is the ID the user requested.
The rtcServer will receive actions ( GET, POST, DELETE and PUT) but the complement with parameters is confusing me.

Another example:  http://www.acme.com/productlist/rtcserver/20151117/dan
The route is http://www.acme.com/productlist , all the rest are parameters.


TIA,
Clément


Title: Re: REST server example
Post by: D.Tkalcec (RTC) on November 18, 2015, 09:59:01 AM
Implement the OnCheckRequest event on the TRtcDataRequest component to evaluate the Request object, which contains all the request headers (Method, FileName, FilePath, Query, Params, ...) and Accept the request if you want to process it with the TRtcDataProvider component, then implement the OnDataReceived event to process the request body (if any) and send out a response. If you don't know how to work with the TRtcHttpServer and TRtcDataProvider components to accept and process requests, start by going through Quick Start examples (available in the FAQ and in the QuickStart folder).

Best Regards,
Danijel Tkalcec