如何使用resty命令行客户端和http rest服务进行交互

本文介绍了如何安装和使用resty命令行客户端来与REST服务进行交互。此外,还提到了其他工具如Postman、Chrome开发者工具和httpbin的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文首发于个人博客https://kezunlin.me/post/4f5f98b9/,欢迎阅读最新内容!

how to install and use resty command line client for interacting with rest services

Guide

install

You have curl, right? Okay.

    curl -L https://raw.githubusercontent.com/micha/resty/master/resty > resty

Source the script before using it.

      . resty

Once resty is installed, set your REST host to which you will be making your requests.

    resty http://127.0.0.1:8080/data
    http://127.0.0.1:8080/data*

And now you can Make some HTTP requests.

    $ GET /blogs.json
    [ {"id" : 1, "title" : "first post", "body" : "This is the first post"}, ... ]
    $ PUT /blogs/2.json '{"id" : 2, "title" : "updated post", "body" : "This is the new."}'
    {"id" : 2, "title" : "updated post", "body" : "This is the new."}
    $ DELETE /blogs/2
    $ POST /blogs.json '{"title" : "new post", "body" : "This is the new new."}'
    {"id" : 204, "title" : "new post", "body" : "This is the new new."}

usage

    source resty [-W] [remote] [OPTIONS]    # load functions into shell
      resty [-v]                              # prints current request URI base
      resty <remote> [OPTIONS]                # sets the base request URI
      HEAD [path] [OPTIONS]                   # HEAD request
      OPTIONS [path] [OPTIONS]                # OPTIONS request
      GET [path] [OPTIONS]                    # GET request
      DELETE [path] [OPTIONS]                 # DELETE request
      PUT [path] [data] [OPTIONS]             # PUT request
      PATCH [path] [data] [OPTIONS]           # PATCH request
      POST [path] [data] [OPTIONS]            # POST request
      TRACE [path] [OPTIONS]                  # TRACE request
      Options:
      -Q            Don't URL encode the path.
      -q <query>    Send query string with the path. A '?' is prepended to
                    <query> and concatenated onto the <path>.
      -W            Don't write to history file (only when sourcing script).
      -V            Edit the input data interactively in 'vi'. (PUT, PATCH,
                    and POST requests only, with data piped to stdin.)
      -Z            Raw output. This disables any processing of HTML in the
                    response.
      -v            Verbose output. When used with the resty command itself
                    this prints the saved curl options along with the current
                    URI base. Otherwise this is passed to curl for verbose
                    curl output.
      --dry-run     Just output the curl command.
      <curl opt>    Any curl options will be passed down to curl.

Other Tools

postman

Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster

download Postman-linux-x64-7.10.0.tar.gz from here

    tar xzvf Postman-linux-x64-7.10.0.tar.gz
    cd Postman
    ./Postman

now we can create free account and play with postman.

chrome developer tools

F12--->Network.

httpbin

A simple HTTP Request & Response Service.

see httpbin

Reference

History

  • 20191106: created.

Copyright

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值