RejectedSoftware Forums

Sign up

Rest interface generator requires interfaces

Is there a particular reason why the rest interface generator,
URLRouter.registerRestInterface, only works with interfaces?

I don't see a technical reason why just a class or a struct wouldn't
work. I'm not sure what the uses case was when this was created but to
me it just adds extra tedious work, keeping the class and interface in sync.

/Jacob Carlborg

Re: Rest interface generator requires interfaces

Am 09.02.2016 um 21:52 schrieb Jacob Carlborg:

Is there a particular reason why the rest interface generator,
URLRouter.registerRestInterface, only works with interfaces?

I don't see a technical reason why just a class or a struct wouldn't
work. I'm not sure what the uses case was when this was created but to
me it just adds extra tedious work, keeping the class and interface in
sync.

The motivation is to ensure that the client and server implementations
talk over the same interface and to make it more or less impossible to
accidentally misuse it. But this issue has been brought up before and a
possible solution is to generate the interface from the class definition
in cases where it is just overhead. It would then look something like this:

class MyRestAPI : AutoInterface!MyRestInterface {
   ...
}

Re: Rest interface generator requires interfaces

On 2016-02-22 10:56, Sönke Ludwig wrote:

The motivation is to ensure that the client and server implementations
talk over the same interface and to make it more or less impossible to
accidentally misuse it. But this issue has been brought up before and a
possible solution is to generate the interface from the class definition
in cases where it is just overhead. It would then look something like this:

class MyRestAPI : AutoInterface!MyRestInterface {
   ...
}

I would prefer that interface is completely optional. I have the feeling
that it's very common to provide an API without a client. Or where the
client and the server are not written in the same language. That's at
least the use case I have.

It would be great if it worked with structs as well. I have not looked
at the implementation in detail to say if this is feasible.

/Jacob Carlborg