tank-http-client.js is a http client based on needle.js.

  • characteristic

  • Only supports the node environment, the browser cannot run
  • Support chain call
  • unit testcovered
  • Has perfect documentation
  • Install

    npm install tank-http-client.js

    basic example

    //导入
    const thc = require("tank-http-client.js")
    //设置基础URL地址 
    thc.setBaseUrl("http://localhost:3008")
    
    thc.get("/test")
        .query({id: 1})
        .send()
        .then((res) => {
            console.log(res)
        }).catch(err => {
        console.error(err)
    });
    //输出 ->{code: 200, method: 'GET', data: 'get_test', search: '1'}
    async () => {
        const res = await thc.get("/test")
            .query({id: 1})
            .send()
        console.log(res)
    }
    //输出 ->{code: 200, method: 'GET', data: 'get_test', search: '1'}

    more examples

    delete

    //delete
    thc.delete("/test").query({id: 1}).send().then((res) => {
        //res: {code: 200, method: 'DELETE', data: 'delete_test', search: '1'}
    })

    post, put, patch

    //post support put patch 
    // thc.put("/test").xxx.send()
    // thc.patch("/test").xxx.send()
    thc.post("/test")
        .query({id: 1}).data({first: "1", nickname: "wind"}).data({
        name: "tank",
        nickname: "wind body"
    }).send().then((res) => {
        // res:{
        //     code: 200,
        //     method: 'POST',
        //     data: 'post_test',
        //     search: '1',
        //     params: {first: '1', nickname: 'wind body', name: 'tank'}
        // }
    })

    File Upload

    //upload
    thc.post("/upload").query({id: 1})
        .file({
            file1: path.join(__dirname, "tank.png"),
            file2: path.join(__dirname, "tank.png")
        })
        .send()
        .then((res) => {
    
        })
    
    //upload by buffer
    thc.post("/upload").query({id: 1})
        .bufferFile({
            file1: path.join(__dirname, "tank.png"),
            file2: path.join(__dirname, "tank.png")
        })
        .send()
        .then((res) => {
    
        })

#tankhttpclientjs #homepage #documentation #downloads #Http #client #based #Needlejs #News Fast Delivery

Leave a Comment

Your email address will not be published. Required fields are marked *