-
Notifications
You must be signed in to change notification settings - Fork 64
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
Make @http:Payload
annotation optional
#3276
Make @http:Payload
annotation optional
#3276
Comments
The existing resource signature behaviour is quite intuitive and understandable via few rules.
So this will be another information for the user to keep in mind also it brings back some ordering again to the signature which was drop during the redesign. Few followup questions
|
Yes, current rules are simple and straightforward but I am not sure how intuitive they are in this particular context though. Because, for example, in the case of
As mentioned in the issue this only applies to
Then the user has to annotate for each query param. |
I love this feature if we can make the rules simple for the 80% case. What about more constraints:
So, these will work correctly then: resource function get foo(string name, Person p) {
}
resource function post bar(Person p) {
}
resource function post baz(int a, string bar, Person p) {
} |
I noticed your comment that will only apply for post/put/patch. But do we need to put more restrictions than HTTP? If the protocol allows an entity body then we allow it. IIRC that's then all except HEAD. The only place this will be annoying is if I want to bring resource function post foo(string qP1, int qP2, @http:Payload string payload) {
} |
After discussing @jclark, @sanjiva, and others, it was decided not to make
The above rules are introduced thinking about the 80% case. Therefore, in the case of GET requests, those rules are excluded as it is not the 80% case to send a payload with the request. HEAD and OPTIONS are special types of requests designed to get meta information about a resource. The dispatcher handles them in a special way. Therefore, those are also excluded from the above rules as well. |
As in the original issue description, we still need the resource function post student(json student) returns json {
string name = student.Name;
return {Name: name};
} In this case, resource function post student(@http:QueryParam json student) returns json {
string name = student.Name;
return {Name: name};
} Again, this is a very rare scenario, IMO. But for the sake of completeness we need it. |
In addition to that, if user has defined the accessor as HEAD or OPTIONS in resource functions, the request will be catered similar to GET request. Specially the resource which has the HEAD accessor will not send the response payload. Hence we can consider GET, HEAD and OPTIONS as non-entity body accessors |
I would also suggest that an included record param ( |
@shafreenAnfar we should not restrict it to just map typed parameters. Even lists are fine as its very normal to get an array of JSON objects. So how about:
|
For example resource function post(Student[] p) {
} |
I and @chamil321 had a quick chat on this. Yeah, above suggestions are valid suggestions. We will update the rules with those suggestions. When it comes to the list type it is common to have list of primitives (i.e.
|
resource function post student(@http:Query map<json> student) returns json {
string name = student.Name;
return {Name: name};
} I and @shafreenAnfar had a discussion and decided to go ahead with |
@http:Payload
annotation optional for post
, put
and patch
@http:Payload
annotation optional
At the moment when writing a
post
resource function, it is required to do the below.This pattern is common (80% case) for the accessors
post
,put
andpatch
as they all require an entity body. Therefore, what if we say the first parameter of the resource definitions for these accessors is defaulted to@http:Payload
. This means above can be written as follows,If the user wants both entity body and query params, it would look like the below,
Then for the uncommon case (20% case) where the user is not interested in the entity body but the query params,
@http:QueryParam
annotation can be introduced. For example,Any thoughts?
The text was updated successfully, but these errors were encountered: