-
Notifications
You must be signed in to change notification settings - Fork 7
2. Using
Andrii Konovalenko edited this page Apr 12, 2017
·
9 revisions
EasyNet supported: get(), post(), put(), delete() and other methods. As parameters, these methods take an array data, witch form the path of URL. Path may be empty.
// path will be: {host/users/id}
EasyNet.get("users", id).start(new NCallback() {
@Override
public void onSuccess(NResponseModel responseModel) {
}
});
EasyNet.get() returns Request instance. Request implements the pattern "builder", that is, all methods return its instance. Method start takes as an argument NCallback instance. If the request succeeds, the onSuccess method is called. You can get response body and headers from responseModel.
Use NCallback only in specific cases of manual data processing. The following tutorial shows examples of working with automatic data parsing.
EasyNet.post()
.setHost("") // Set base url, example: http://myapi.com
.setPath("essence", 1, "method") // Formed with a host: http://myapi.com/essence/1/method
.setUrl("http://myapi.com/essence/1/method") // Or set full URL
.setMethod("GET") // Change request method dynamically
.setContentType(NConst.MIME_TYPE_MULTIPART_FORM_DATA) // X_WWW_FORM_URLENCODED by default
.addParam("param", "value")
.addHeader("header", "value")
.addQueryParam("queryParam", "value") // Only query params
.addParam("fileName",new File("path")) // For multipart requests
.addParams(new HashMap<String, String>()) // Params as Mapped object
.setReadTimeout(5000) // Change default read timeout value
.setConnectTimeout(5000); // Change default read timeout valueDo not copy this code. All methods are mixed for an example.