7 Star 18 Fork 8

黄海彬 / Elegant

加入 Gitee
与超过 600 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
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.

仓库评论 ( 0 )

你可以在登录后,发表评论

简介

Java原生的Http网络框架,底层基于HttpNet,动态代理+构建的,致敬Square的Retrofit,同样的用法,不一样的实现! 展开 收起
Android
Apache-2.0
取消

发行版

暂无发行版

Elegant

贡献者

全部

近期动态

加载更多
不能加载更多了
Android
1
https://gitee.com/huanghaibin_dev/Elegant.git
git@gitee.com:huanghaibin_dev/Elegant.git
huanghaibin_dev
Elegant
Elegant
master

搜索帮助