Git Product home page Git Product logo

walkman's Introduction

MELPA abrochard

Walkman

Write HTTP requests in Org mode and replay them at will using cURL

walkman demo gif

Features

  • write HTTP requests as org mode "walkman entries"
  • execute walkman entries via curl
  • export walkman entries to a curl command
  • import curl command to walkman entries (beta)
  • support lisp variable or functions in a walkman entry
  • execute a series of lisp callbacks, passing the status code, headers, and response body

Installation

Load up the walkman.el file.

Usage

By default, after calling M-x walkman-setup, these bindings will be added to org-mode:

C-c C-RETURN   to execute the entry at point
C-c C-'        for the walkman menu
C-c C-' c      to copy the entry at point as a curl command
C-c C-' i      to import a curl command and insert as walkman entry

How to write a walkman entry

See the sample.org file for example of walkman entries.

The general structure is

* Request Title
  GET/POST/PUT/... URL
  - Header1: value
  - Header2: value
  :FORM:
  - type: document
  - file: [[/home/user/document.jpg]]
  :END:
  #+begin_src
    {
      "body": "in any mode/format"
    }
  #+end_src
  1. First Callback
     #+begin_src emacs-lisp
       (lambda (status headers body)
         (message "status %s, headers %s, body %s" status headers body))
     #+end_src
  2. Second Callback
     #+begin_src emacs-lisp
       (lambda (status headers body)
         (message "Second callback"))
     #+end_src

Note that only the HTTP action and URL are required, everything else is up to you.

Simple GET request

* Simple GET request
  GET https://httpbin.org/get

Simple POST request with JSON body

* Simple POST request
  POST https://httpbin.org/post
  - Accept: application/json
  - Content-Type: application/json
  #+begin_src json
    {
      "data": {
        "title": "Hello",
        "hello": "world"
      }
    }
  #+end_src

Multipart upload

You can upload multipart document using the :FORM: Org drawer syntax:

* Multi part
  POST https://httpbin.org/post
  - Accept: application/json
  :FORM:
  - type: document
  - file: [[/home/username/sample_document.jpg]]
  :END:

will result in

curl --silent -i -X POST https://httpbin.org/post -F 'file=@/home/username/sample_document.jpg' -F 'type=document' -H 'Accept: application/json'

Things to know:

  1. Headers inside the org drawer :FORM: will be set with the curl -F flag for form
  2. org links to file will get their path prefixed with a @
  3. :FORM: headers must be AFTER regular headers for the parser to work properly

This is an example that will not work:

* Wrong multi part
  POST https://httpbin.org/post
  :FORM:
  - file: [[/home/username/sample_document.jpg]]
  :END:
  - Accept: application/json

because the Accept header will not be parsed correctly.

Request with lisp variable

Define my-http-status with

(setq my-http-status "400")

OR specify a file variable and run

* Embedded lisp variable
  GET https://httpbin.org/status/`my-http-status`

Request with callbacks

* Request with callbacks
  POST https://httpbin.org/post
  #+begin_src json
    {
      "some": "body"
    }
  #+end_src
  1. First callback
     #+begin_src emacs-lisp
       (lambda (status headers body)
         (message "status %s, headers %s, body %s" status headers body))
     #+end_src
  2. Second callback
     #+begin_src emacs-lisp
       (lambda (status headers body)
         (pp (assoc 'url (json-read-from-string body))))
     #+end_src

Customization

Always keep the headers

If you don't want to bother with the -v flag to keep the headers in the response buffer, you can do

(setq walkman-keep-headers t)

Custom key bindings

By default, running walkman-setup will run

(define-key org-mode-map (kbd "C-c C-'") #'walkman-transient)
(define-key org-mode-map (kbd "C-c <C-return>") #'walkman-at-point)

If you want to setup your own binding, don't run walkman-setup and instead bind

  • walkman-at-point for quick execution under the cursor
  • walkman-transient for the transient-based interactive menu

TODO

  • insert response in org doc?
  • execute all requests sequentially
  • unit tests
  • option to run async
  • multiple backends

Similar projects

walkman's People

Contributors

abrochard avatar conao3 avatar dcaixinha avatar stig avatar tarsius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

walkman's Issues

how to do requests with certificates?

I need to do requests using certificates: how could I do them?

How could I add extra options to curl (like -K filename) ?

Thanks in advance
Matteo

byte compiler warning: functions are not known to be defined: json-pretty-print, json-mode

I just installed walkman via M-x package-install and encountered this warning:

walkman.el:365:1:Warning: the following functions are not known to be defined:
    json-pretty-print, json-mode

json-pretty-print is from json.el so it needs to be loaded. and json-mode is provied by a third party package json-mode, which is not avaliable if user does not installed by themself.

Callbacks don't work when FORM drawer is present

Hey @abrochard, it's me again ๐Ÿ˜„

Having the following snippet:

* Some request
  POST http://some-url
  - Authorization: Bearer `my-token`
  :FORM:
  - type: document
  - file: [[/home/dcaixinha/test_document.png]]
  :END:
  1. First callback
    #+begin_src emacs-lisp
      (lambda (status headers body)
        (message "status %s, headers %s, body %s" status headers body))
    #+end_src

I can't get the callback to run. I've copied it from the sample.org file, but it always errors with:

walkman--parse-response: Search failed: "^HTTP/[0-9]\\.?[0-9]? \\([0-9]\\{3\\}\\) \\([A-Z ]+\\)?"

If I remove the :FORM drawer from the request than everything works. I've tried looking at the function that's giving the error but couldn't figure out why having the drawer there yields an error. Can you help me out pleas? ๐Ÿ™

Add support to parse JSON output

Whenever I do a request that receives a huge JSON payload in the body, I have to copy it and format it in some other way to make it readable. Is there already some way to do this currently with walkman? The usual way to do this in cURL is piping it to some other tool (like jq or json_pp). Maybe walkman could support something similar (that would be configurable)? Thanks ๐Ÿ™

Add support for multi-part file uploads

Hey @abrochard, first of all thank you for this really cool package ๐Ÿ™Œ (and I'm also a fan of kubel ๐Ÿ˜„)

I have to interact with a lot of APIs that require the upload of files through multi-part. Is that something that's easy / feasible to add in this library? I didn't study it yet, and I don't know the backend for making the requests, but I can try to provider some cURL examples of what I'd like to have.

Thanks again ๐Ÿ™‡โ€โ™‚๏ธ

Add support for async requests

Hey @abrochard,

I want to stop just asking for stuff and try to start contributing. I want to tackle something that you have in your TODO in the README: adding support for async requests. Do you already have an idea on how to accomplish this?

From my quick research there's two packages that might be interesting to look at:

What's your opinion on the above? Thanks! ๐Ÿ™

How to set variable per file / heading?

Hey @abrochard, this isn't exactly a bug but more of a help request.

Before using walkman I used to use File Variables to have a different file for staging and production API (setting the URLs and tokens with variables accordingly). I was trying to do the same with walkman but apparently the variable needs to be global. For example I would have a staging.org file with:

-*- walkman-api-url: "https://some-api"; walkman-api-token: "bogus_token" -*-

* Simple GET
  GET `walkman-api-url`/some-get-endpoint
  - Authorization: Bearer `walkman-api-token`

But then I get Symbol's value as variable is void: walkman-api-url. I was also thinking that the same could be achieved by having some sort of pre-request hook and then have all the environments in the same file. For example in http.org I would wave:

* Staging
** Simple GET
  <some hook to set `walkman-api-url` and `walkman-api-token`
  GET `walkman-api-url`/some-get-endpoint
  - Authorization: Bearer `walkman-api-token`
* Production
** Simple GET
  <some hook to set `walkman-api-url` and `walkman-api-token`
  GET `walkman-api-url`/some-get-endpoint
  - Authorization: Bearer `walkman-api-token`

Which one would you say is the best way @abrochard? Or would you do this differently? Thanks ๐Ÿ™‡โ€โ™‚๏ธ

Crashing on Emacs 28

Hi ๐Ÿ‘‹

I've recently updated to Emacs 28 and I can't seem to use any of the walkman commands anymore.

First it said that the Lisp nesting level was exceeded. I bumped the max-lisp-eval-depth variable, and then also needed to bump the max-specpdl-size. Afterwards, I still get Re-entering top level after C stack overflow when trying any walkman command - even just trying to copy the command to curl.

Any hints on what's happening?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.