Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Conversation

@WonderCsabo
Copy link
Member

@PathParam: allows to add different url variable name than the method parameter name. It can be expanded later to use url encoding.

@Post("/login{id}")
void login(User user, @Path("id") String identifier);

@Field: allows to add post parameters as method parameters, just like url variables. Form data and multipart data are supported.

@Post("/login")
void login(@Field String username, @Field String password);

About multipart: currently, it requires some boilerplate, but much less than before:

@Post("/profilepicture")
@RequiresHeader("Content-Type")
void upload(@Field String name, @Field FileResource picture);

userRestClient.setHeader("Content-Type", MULTIPART_FORM_DATA);
// normal calls

It would be better to remove the need for this.

  • we could use 323 custom rest headers #967, to add @Headers(@Header(headerName = "Content-Type", value = MULTIPART_FORM_DATA ))
  • create a @Part annotation which automatically adds the header, and works like @Field
  • multi-part post flag for @Post which adds the header
  • add the header if the parameter type is Resource
  • combination of them

I am open to any suggestions.

Implements #1438.

@WonderCsabo WonderCsabo force-pushed the 1438_restFormParamAnnotation branch 3 times, most recently from 3be3e1a to 3ed9709 Compare June 10, 2015 16:46
@WonderCsabo WonderCsabo force-pushed the 1438_restFormParamAnnotation branch from 3ed9709 to 624acaf Compare June 16, 2015 19:03
@WonderCsabo
Copy link
Member Author

@yDelouis @dodgex any feedback about multipart?

@yDelouis
Copy link
Contributor

I would add the annotations @Headers and @Header for that.
I would have named the new annotation @Post.Param @FormParam.

@WonderCsabo
Copy link
Member Author

@yDelouis adding that header again and again is a little bit dumb i think. Maybe we should create @MultiPart which behaves exactly like @Post.Param, just adds the header automatically. Like retrofit.

@yDelouis
Copy link
Contributor

With retrofit, according to the main page, you have to add @MultiPart and @Part for each param.
What about copying what they did :

  • add @PathParam for replacing a placeholder in the url (or keep it as it is, without any annotation).
  • add @Field for form post request.
  • add @Part for multipart parts.
  • add @UrlParam for url params.

@Fieldand @Part are incompatible.
And the headers would be added automatically.

Maybe we should wait the plugin system also.

@WonderCsabo
Copy link
Member Author

What is the difference between @PathParam and @UrlParam?

@yDelouis
Copy link
Contributor

@PathParam replaces a placeholder, like we do now without annotation.
@UrlParam add will add ?name=value or &name=value to the url.

@WonderCsabo
Copy link
Member Author

Are you sure @UrlParam is needed? It is still achievable with @PathParam. For complex queries, we should implement @QueryMap (#900). Actually @UrlParam is also nice, but @QueryMap is more important i think.

I rename @Post.Param to @Field and implement @Part.

@WonderCsabo WonderCsabo force-pushed the 1438_restFormParamAnnotation branch from 624acaf to 70cee67 Compare June 17, 2015 21:48
@WonderCsabo WonderCsabo changed the title Add @Post.Param and @PathParam Add @Field and @PathParam Jun 17, 2015
@yDelouis
Copy link
Contributor

@UrlParam is not necessary but would be convenient.
@QueryMap would be nice too.

@WonderCsabo
Copy link
Member Author

These two would only work with @Get, am i right?

@yDelouis
Copy link
Contributor

No, this could be used with @Post also. In my company, the webservices are not really REST services and we have to post data with url params.

@WonderCsabo
Copy link
Member Author

Well, in that case we could allow it for any HTTP method.

@WonderCsabo
Copy link
Member Author

I realized that we already use the "url variable" term for path parameters in the existing code and messages. Maybe we should use @QueryParam instead of @UrlParam?

@WonderCsabo WonderCsabo force-pushed the 1438_restFormParamAnnotation branch from 35201be to bad67c5 Compare June 23, 2015 20:32
@WonderCsabo
Copy link
Member Author

This PR is already big. The work for @Path, @Field and @Part is complete. I will add @Query and @QueryMap if you merge this, @yDelouis.

@yDelouis
Copy link
Contributor

Okay for making another PR.

@WonderCsabo WonderCsabo force-pushed the 1438_restFormParamAnnotation branch 2 times, most recently from 37aebd9 to bd903b1 Compare June 23, 2015 23:41
@WonderCsabo WonderCsabo changed the title Add @Field and @PathParam Add @Field, @Part and @Path Jun 24, 2015
@WonderCsabo
Copy link
Member Author

@yDelouis i am starting to think we should require annotations for all method parameters in a REST method. That way the AA code would be more simpler, and also it would be much more clearer for the caller how to use the parameters. It will break the API, but users will see the change and the necessary actions at compile-time.

@yDelouis
Copy link
Contributor

You're right. And with the plugin system, we are breaking everything so we shouldn't worry about that.

@WonderCsabo
Copy link
Member Author

👍

@WonderCsabo WonderCsabo force-pushed the 1438_restFormParamAnnotation branch from bd903b1 to 8e2d87c Compare September 11, 2015 18:36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you put process before validate ? It's a bit strange to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, i do not know why i did it.

@yDelouis
Copy link
Contributor

It seems good. Could you rebase and address my comments.
When done, you can merge it by yourself to be sure you won't have to rebase twice.
We will have to edit the wiki then.

@WonderCsabo WonderCsabo force-pushed the 1438_restFormParamAnnotation branch from 8e2d87c to c2fe71e Compare September 21, 2015 10:04
@WonderCsabo WonderCsabo merged commit 774f80f into androidannotations:develop Sep 21, 2015
@WonderCsabo WonderCsabo deleted the 1438_restFormParamAnnotation branch September 21, 2015 10:15
@WonderCsabo WonderCsabo added this to the 4.0 milestone Sep 21, 2015
@WonderCsabo
Copy link
Member Author

Wiki edited.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants