Blog

All Blog Posts  |  Next Post  |  Previous Post

Something I forgot to say about TMS XData 4.5 regarding URL endpoints

Monday, June 24, 2019

Well, actually I didn't forget it. I was just not blog about it.

But since we got a very positive feedback in the last post about new features in TMS XData 4.5, I decided to show you an extra thing, somewhat related to the parameter binding feature: it's the new EnableKeyAsSegment property.

Basically it controls how the endpoint URL for entities will look like. Let's take the SQLiteConsoleServer demo as an example. It automatically publishes all tables in the database without a single line of code, as Aurelius entities. If you run the demo and navigate to the swaggerui address you will see the available endpoints. In the screeshot below we can see the ones for Album entity:



Now let's see what happens when we set EnableKeyAsSegment property to True:

  XDataServer1.EnableKeyAsSegment := True;
If you recompile, run the demo again and refresh the browser page to update SwaggerUI interface, here is what you get:



Did you notice the difference?

Yep, the URL format was /Album(2) - the id enclosed in parenthesis - and now it is /Album/2. Everything works just as before, and both URL are valid REST addresses, but having the ID in the path is a more common approach out there and might be easier for you to integrate with existing non-Delphi frameworks.

For entities with composite keys, you put one id in each path segment. For example, suppose you have an entity Order which is identified by CustomerId (string) and OrderNo (integer). Instead of using the URL /Order(AFKLI,2) you can use /Order/AFKLI/2.

As one final note, when you enble the new URLs, the old ones are still valid. It's not a replacement, but an addition. The exception is in the SwwaggerUI itself, which hides the URLs using parenthesis to not clutter the UI too much.

Hope you liked this one, two!


Wagner Landgraf




This blog post has received 2 comments.


1. Monday, June 24, 2019 at 11:45:05 PM

double wow! ;-)

Very great work Wagner!

Piffer Claudio


2. Tuesday, June 25, 2019 at 1:28:13 AM

Thanks, Claudio! ;-)

Wagner R. Landgraf




Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post