项目作者: alishatergholi

项目描述 :
Type-safe HTTP client for Android and Java by Square, Inc.
高级语言: Java
项目地址: git://github.com/alishatergholi/rest-client.git
创建时间: 2018-10-14T11:29:01Z
项目社区:https://github.com/alishatergholi/rest-client

开源协议:

下载


RestClient

Type-safe HTTP client for Android and Java by Square, Inc.

implement Oauth2 Authorization

download

Gradle
latest version on jitpack

  1. repositories{
  2. maven { url 'https://jitpack.io' }
  3. }
  4. //java version required
  5. compileOptions {
  6. sourceCompatibility = JavaVersion.VERSION_1_8
  7. targetCompatibility = JavaVersion.VERSION_1_8
  8. }
  9. dependencies {
  10. implementation 'com.github.alishatergholi:rest-client:1.1.5'
  11. }

How do i use RestClient

  1. RestClient client = new RestClient
  2. .Builder(context)
  3. /* for add custom header you need
  4. ArrayMap<String,String> header = new ArrayMap<>();
  5. header.put("appid","0e8f8fd2-1acb-11e7-8ab0-ac162d7938f0");
  6. header.put("accept-language", "fa");
  7. .setHeader(header)
  8. */
  9. /* for add Authorization Header */
  10. .setAuthorization("Authorization url","clientId","client",AuthType.BASIC_AUTH)
  11. .setUserInfo("username for Authorization","password for Authorization")
  12. .build();
  13. //for add body use.
  14. RequestParams params = new RequestParams(RequestBodyType.FormData);
  15. params.put("key","value");
  16. client.POST("url",
  17. "tag " /*you can set tag when you need to cancel your service*/,
  18. params /* except get method we can add body for other method as body */,
  19. new ResponseTextHandler() {
  20. @Override
  21. protected void onSuccess(String result) {
  22. Log.d(TAG,result);
  23. }
  24. @Override
  25. public void onProgress(double percent, long bytesWritten, long totalSize) {
  26. super.onProgress(percent, bytesWritten, totalSize);
  27. Log.d(TAG,"percent " + percent);
  28. }
  29. @Override
  30. public void onFailure(int errorCode, String errorMsg) {
  31. Log.d(TAG,"onFailure " + errorMsg);
  32. }
  33. });

License

  1. Copyright 2013 Square, Inc.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.