Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing of response of service resource #278

Closed
jclark opened this issue Jul 26, 2019 · 5 comments
Closed

Typing of response of service resource #278

jclark opened this issue Jul 26, 2019 · 5 comments
Labels
Area/Lang Relates to the Ballerina language specification grpc Improves support for gRPC and protocol buffers

Comments

@jclark
Copy link
Collaborator

jclark commented Jul 26, 2019

The type of a service resource method does not make explicit the type of the response that the resource method will send to a client when it is invoked.

This is not a good fit for gRPC and will likely cause problems for session typing across Ballerina programs.

@sanjiva points out that “using return has the problem that the code doesn't know whether return succeeded - that's why it was done that way from the start”

@jclark jclark added Area/Lang Relates to the Ballerina language specification grpc Improves support for gRPC and protocol buffers labels Jul 26, 2019
@sanjiva
Copy link
Contributor

sanjiva commented Jul 26, 2019

With our current approach we don't also have a way to record say media type + content schema of responses.

That's what Swagger calls "produces": https://swagger.io/docs/specification/2-0/basic-structure/.

@jclark
Copy link
Collaborator Author

jclark commented Jul 26, 2019

I haven’t thought this through, but the Swagger “produces” concept triggered the following idea:

  1. allow a resource method to say produces T in addition to returns T.
  2. have a produce action, analogous to a return statement
  3. since it’s an action, it can return an error (but what can you do if it does return an error?)

@sanjiva
Copy link
Contributor

sanjiva commented Jul 26, 2019

Yes I was thinking along the lines of your point 1 too.

Ref the action, there are protocol specific actions currently to actually send the response and given the different kinds of replies based on protocol and the terminology used: http - respond, grpc - send but maybe that's fixable. The signatures would not match of course.

Ref point 3, if the action returns an error then the resource function returns an error. In that case the protocol driver (which is the one that invokes the resource function in the first place) is responsible for responding / negotiating the protocol properly. For HTTP that might be simply to return 500 server error. For a lower level protocol it may be just to close the socket.

@jclark
Copy link
Collaborator Author

jclark commented Nov 20, 2019

If you are writing a client and service in Ballerina, it would be nice if the service declaration could be used as a client declaration.

@jclark
Copy link
Collaborator Author

jclark commented Sep 26, 2020

This is handled by #612. We drop the requirement that resource methods (which become service remote methods) return a subtype of error?. This allows them to use the return value to describe the response. This works only when for a request/response message exchange pattern. For more complex patterns, the resource method should be passed a strongly typed client.

@jclark jclark closed this as completed Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification grpc Improves support for gRPC and protocol buffers
Projects
None yet
Development

No branches or pull requests

2 participants