-1

I want to use @Rest api from android annotations to post application/json data to server. How can I do it? I want something like POST request send json data java HttpUrlConnection but as simple as android annotations.

thanks.

3 Answers 3

2

You can user Retrofit Type-safe REST client for Android and Java.

Use annotations to describe the HTTP request:

  • URL parameter replacement and query parameter

support Object

  • conversion to request body (e.g., JSON, protocol buffers)
  • Multipart request body and file upload

See here a good tutorial Consuming-APIs-with-Retrofit

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, wow it seems to be such a good library. I'm going to use it. thanks
yes it is a great lib I have used a lot in my app. You're welcome! If you can accept the answer =)
1

You can use Gson library for this. Here and here you can find useful tutorials.

Comments

1

Actually i think this is well documented in the AA wiki.

@Rest(rootUrl = "http://company.com/ajax/services", converters = { GsonHttpMessageConverter.class })
public interface MyRestClient {

  @Post("/events")
  void addEvent(Event event);
}

public class Event {
  String description;

  // ...
}

You you can use MappingJacksonHttpMessageConverter instead of GsonHttpMessageConverter if you are using Jackson instead of GSON.

Disclaimer: i am an AndroidAnnotations developer.

3 Comments

Could you tell me why you cannot use post with a set of arguments in the same way as Retrofit or a GET request? Why does AA have the need for a Post arguments class?
Post parameter annotation is added in the next release of AA. If you need new features, feel free to contribute, as all AA developers do in their free time.
I didn't want to come off as needy and if I did, I apologize. You do great work with AA! Thank you very much for your good work and your quick response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.