Exposing service as JSON.. recommended way


when I’m intend to expose my service as JSON (also)… what way is recommended/preferred/more suitable to use… TROJSONMessage or TROHttpApiDispatcher? Can You compare it, explain cons & pros of both, describe scenarios of usage, differences of purpose? Coming with HttpApi (9.3 release), should be TROJSONMessage considered as obsolete?

I’ve found and read some articles about this, e.g.:
…but its a bit brief to clear all questions & answers.

Thanks, regards from Prague


You can consider HttpAPI as a very advanced wrapper over the bare JSON message.

TROHttpApiDispatcher for sure, especially if you need to provide API for 3rd party developers / tools

Main pros:

  • It turns your server into a REST server with almost no code
  • It allows to return custom success or failure Http response codes (with JSON message you’ll be locked on 200 OK and 502 ERROR only)
  • It supports different Http methods (GET, POST, PUT, DELETE) while JSON message accepts only POST
  • If needed it is even possible to return raw data stream with optional ContentType set. This means that HttpAPI can return f.e. PDF document or a jpeg image and the browser will recognize it properly
  • HttpAPI generates server API description for you in the OpenAPI format that can be used later to generate client implementations using f.e. Swagger
  • The last but not the least - all and any web frameworks that can fetch JSON data from the server will be able to talk natively to HttpAPI server (Angular, React, Vue.js and so on)

Data Abstract is not supported out of the box for now. There’s some things for this under development, but for now it would require some code from you if you’ll need to access Data Abstract server via HttpAPI



thanks for explanation… ability to use different HTTP methods, serving API description… important pros, agree.

As I could see, there is topic in online documentation (https://docs.remotingsdk.com/Servers/Concepts/HttpAPI/SampleDelphi/) which explains steps how to expose JSON service in CodeFirst server… but if I’m not mistaken, HttpApi can be used as well as in “old-fashioned” servers, built around classic RODL libraries…?

Greetings from Prague

You’re right.
As you can see from the doc, to expose a method via HttpAPI in a code-first server one needs to add a certain attribute to its definition.

For RODL-based servers the approach is similar. You need to open the server RODL in service builder, select a method and press the Attributes button. Then set required attributes and everything should work just fine.