Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
News

New RAD Server Features in RAD Studio 10.3

the future of starts demands massive productivity

The version of RAD Server that ships with RAD Studio 10.3 offers a very significant set of enhancements, mostly focused on how a resource (and have a URL) is mapped to classes and methods on the server. While the key idea of having classes (or data modules) that implement resources remains the same, there are two new approaches:

  • First, you can now map the same URL and HTTP Verb to multiple method handlers, based on content type and accept types HTTP headers. As a side change, you can also freely map HTTP verbs to custom methods names.
  • Second, rather then implementing the actual methods for the HTTP verbs in the resource class, they can be forwarded to a separate and possibly shared implementation class, which needs to support a specific interface. To further simplify things, RAD Studio includes ready to use components for files and datasets management

In this blog post I don’t want to cover all of the options, but just guide you through same example I wrote for my CodeRage 2018 session on RAD Server – the entire source code is also available on GitHub at https://github.com/marcocantu/DelphiSessions/tree/master/RADServer103CodeRage.

Using Multiple Accept Types with EndpointProduce

One of the new features I mentioned above is the ability to have the same exact URL mapped to different methods depending on some HTTP headers. For a GET operation, you can discriminate on the content type indicated in the Accept HTTP header. You do so by decorating the methods with the EndpointProduce attribute plus a related MIME type.

This is the example of a class accepting either images or general data (for Chrome at least application/xml is in any general call):

The implementation of these methods is rather trivial, as all the code does is return a file:

How can you test it? Certainly not just pointing your browser to the URL – if you do you invariably receive the result of the second method, but you might also get an error message indicating that none of the available endpoints matches the request. For a simple test, I wrote the following HTML code, which refers to the same URL in two different ways the browser resolves with different Accept headers in the request: