Hi,
I am working on a REST implementation using Data Abstract in Delphi 10.4. One of the things I’m trying to plan is allowing a new version of various endpoints to exist within the same application. I am using code first, and I’m curious if there is a best practice or a built-in versioning feature that handles allowing multiple versions of the same endpoint within the same application?
The current design puts the version into the URL:
if I have a change to foo, I’d like to have a new version for both endpoints, and bar would inherit the behavior from v1:
- https://example.com/v1/foo
- https://example.com/v1/bar
- https://example.com/v2/foo (new behavior)
- https://example.com/v2/bar (same as /v1/bar)
I can subclass the existing Service to a new class and put the new methods there, with the HttpApiPath updated to ‘v2’. I have this working, and seems like it would work well when there is a breaking change and a method needs to be updated/changed.
TVersion1Test = Class(TDataAbstractService)
[ROServiceMethod]
[ROCustom('HttpApiMethod','POST')]
[ROCustom('HttpApiPath','v1/foo')]
procedure foo; virtual;
[ROServiceMethod]
[ROCustom('HttpApiMethod','POST')]
[ROCustom('HttpApiPath','v1/bar')]
procedure bar; virtual;
TVersion2Test = Class(TVersion1Test)
[ROServiceMethod]
[ROCustom('HttpApiMethod','POST')]
[ROCustom('HttpApiPath','v2/foo')]
procedure foo; override; // will impelement new stuff
[ROServiceMethod]
[ROCustom('HttpApiMethod','POST')]
[ROCustom('HttpApiPath','v2/bar')]
procedure bar; override; // will call inherited
If we assume that procedure Bar() is the same in TVersion1Test and TVersion2Test, is there a way to register the new HttpApiPath for ‘v2/bar’ with the existing TVersion1Test.Bar() method? This way, I would only need to declare methods that actually change between versions.
I was wondering if I could re-declare the HttpApiPath on the existing class, but this seems to replace the existing HttpApiPath, which isn’t surprising:
TVersion1Test = Class(TDataAbstractService)
[ROServiceMethod]
[ROCustom('HttpApiMethod','POST')]
[ROCustom('HttpApiPath','v1/foo')]
procedure foo; virtual;
[ROServiceMethod]
[ROCustom('HttpApiMethod','POST')]
[ROCustom('HttpApiPath','v1/bar')] // no longer works
[ROCustom('HttpApiPath','v2/bar')] // works
procedure bar; virtual;
TVersion2Test = Class(TVersion1Test)
[ROServiceMethod]
[ROCustom('HttpApiMethod','POST')]
[ROCustom('HttpApiPath','v2/foo')]
procedure foo; override; // will impelement new stuff
Thanks for any input,
Leo