restc docs

  1. [import]

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/yimicat/restc.js/dist/restc.min.js"></script>
    
  2. [setOptions]

    /**
     * rest初始化
     */
    var token = 'eyJhbGciOiJIUzI1NiJ9';
    restc.setOptions({
        baseUrl : 'http://localhost:8080/api/', //api的url
        headers: {
            authorization: token //token
        }
    });
    
  3. [post]

    /**
     * 获取用户列表
     * [POST] http://localhost:8080/api/user
     */
    restc.post({
        url: 'user',
        success: function (result) {
            //成功执行的代码
            console.log(result)
        },
        error:function() {
            //失败执行的代码
        }
    });
    
  4. [get]

    /**
     * 查询用户编号为1的用户
     * [GET] http://localhost:8080/api/user/1
     */
    restc.get({
        url: 'user/{userId}',
        params: {userId: 1},
        success: function (result) {
            console.log(result)
        },
        error:function() {
    
        }
    });
    
  5. [put]

    /**
     * 新增用户
     * [PUT] http://localhost:8080/api/user
     */
    restc.put({
        url: 'user',
        data : {
            'userName' : 'testuser',
            'userRealName' : '测试用户',
            'sex' : 'W',
            'depId' : '1',
            'phone': '1862348702'
        },
        success: function (result) {
            console.log(result)
        },
        error:function() {
    
        }
    });
    
  6. [patch]

    /**
     * 禁用编号为1的用户
     * [PATCH] http://localhost:8080/api/user/1
     */
    restc.patch({
        url: 'user/{userId}',
        params: {userId: 1},
        data : {status : "N"},
        success: function(result) {
            console.log(result)
        },
        error : function (result) {
        }
    });
    
  7. [del]

    /**
     * 删除编号为1的用户
     * [DELETE] http://localhost:8080/api/user/1
     */
    restc.del({
        url: 'user/{userId}',
        params: {userId: 1},
        success: function (result) {
            console.log(result)
        },
        error:function() {
    
        }
    });
    
  8. 重写error

    /**
     * 重写error
     */
    restc.post({
        url: 'user',
        success: function (result) {
            console.log(result)
        },
        error : function() {//重写error
    
        }
    });
    
TOP