Most Recent Post  |  Next Post  |  Previous Post  |  Index List

TMS XData 4.5: Parameter Binding and SwaggerUI


Wednesday, June 19, 2019

TMS XData 4.5 has been released with two major new features: parameter binding and Swagger UI.

SwaggerUI is a great new addition, just by setting two simple properties in TXDataServer component (you can do it from the object inspector at design-time):
XDataServer1.SwaggerOptions.Enabled := True;
XDataServer1.SwaggerUIOptions.Enabled := True;
A new endpoint "swaggerui" is added to your API. Just navigate to it and you will get the nice SwaggerUI which automatically displays all your API endpoints, how they should invoke, which parameters they receive, and even more, test it right away, from the browser:

Parameter Binding
Flexible parameter binding via attributes is another nice addition that provides you more control on how the API method must be invoked via raw HTTP requests - note that if you use Delphi XData Client or TMS Web Core XData Web Client, this is transparent to you, you just specify the method and parameter, and binding and routing is automatic.

But if you intend to call your API from non-Delphi platforms, you can now fully control how it works. You can declare methods like this:

  procedure Process(
    [FromPath] PathA: Integer; 
    [FromQuery] QueryA: string;
    BodyA, BodyB: string;
    [FromQuery] QueryB: Boolean;
    [FromPath] PathB: string;
  ): double;
And that means the action would be invoked with a request like this:

POST /tms/xdata/MyService/Process/5/value?QueryA=queryvalue&QueryB=true HTTP/1.1
  "BodyA": "one",
  "BodyB": "two"
Note how FromPath, FromQuery (and implicit FromBody) parameter changes the parameter binding so that the API knows that PathA and PathB parameters are 5 and value respectively (coming from the URL path), QueryA comes from the query string, and BodyA and BodyB comes from JSON in request body.

If you want to see both parameter binding and SwaggerUI in action, take a look at this new video about it:

Wagner R. Landgraf


This blog post has received 6 comments. Add a comment.

Most Recent Post  |  Next Post  |  Previous Post  |  Index List