Watch 1 Star 2 Fork 8

刘近冲 / ElegantApache-2.0

forked from 黄海彬 / Elegant 
Join us
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
Java原生的Http网络框架,底层基于HttpNet,动态代理+构建的,致敬Square的Retrofit,同样的用法,不一样的实现! spread retract

Clone or download
Loading...
README.md

#Elegant项目结构如下 输入图片说明

Elegant采用Retrofit动态代理+构建的思想,本身并不做网络请求,网络部分基于HttpNet实现,本着简洁清晰的思想,保持了和Retrofit相似的API

##gradle

compile 'com.haibin:elegant:1.1.9'

##创建API接口

public interface LoginService {
     
    //普通POST
    @Headers({"Cookie:cid=adcdefg;"})
    @POST("api/users/login")
    Call<BaseModel<User>> login(@Form("email") String email,
                                @Form("pwd") String pwd,
                                @Form("versionNum") int versionNum,
                                @Form("dataFrom") int dataFrom);

    // 上传文件                           
    @POST("action/apiv2/user_edit_portrait")
    @Headers("Cookie:xxx=hbbb;")
    Call<String> postAvatar(@File("portrait") String file);

    
    //JSON POST
    @POST("action/apiv2/user_edit_portrait")
    @Headers("Cookie:xxx=hbbb;")
    Call<String> postJson(@Json String file);
    
    //PATCH
    @PATCH("mobile/user/{uid}/online")
    Call<ResultBean<String>> handUp(@Path("uid") long uid);
}

##执行请求

public static final String API = "http://www.oschina.net/";
public static Elegant elegant = new Elegant();

static {
    elegant.registerApi(API);
}

LoginService service = elegant.from(LoginService.class)
                              .login("xxx@qq.com", "123456", 2, 2);
                              .withHeaders(Headers...)
                              .execute(new CallBack<BaseModel<User>>() {
                                      @Override
                                      public void onResponse(Response<BaseModel<User>> response) {
                
                                      }

                                      @Override
                                      public void onFailure(Exception e) {

                                      }
                              });

##Licenses

  • Copyright (C) 2013 huanghaibin_dev huanghaibin_dev@163.com

  • Licensed under the Apache License, Version 2.0 (the "License");

  • you may not use this file except in compliance with the License.

  • You may obtain a copy of the License at

  •     http://www.apache.org/licenses/LICENSE-2.0
  • Unless required by applicable law or agreed to in writing, software

  • distributed under the License is distributed on an "AS IS" BASIS,

  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  • See the License for the specific language governing permissions and limitations under the License.

Comments ( 0 )

Sign in for post a comment

1
https://gitee.com/LiuJinChong/Elegant.git
git@gitee.com:LiuJinChong/Elegant.git
LiuJinChong
Elegant
Elegant
master

Help Search