ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Request

by twolfson ALL

Make HTTP requests from Sublime Text

Labels http, url

Details

Installs

  • Total 10K
  • Win 7K
  • Mac 2K
  • Linux 738
Jun 14 Jun 13 Jun 12 Jun 11 Jun 10 Jun 9 Jun 8 Jun 7 Jun 6 Jun 5 Jun 4 Jun 3 Jun 2 Jun 1 May 31 May 30 May 29 May 28 May 27 May 26 May 25 May 24 May 23 May 22 May 21 May 20 May 19 May 18 May 17 May 16 May 15 May 14 May 13 May 12 May 11 May 10 May 9 May 8 May 7 May 6 May 5 May 4 May 3 May 2 May 1 Apr 30
Windows 0 0 0 0 2 0 0 0 2 0 1 1 2 1 0 2 2 0 0 0 0 0 1 0 0 2 1 0 0 1 0 0 0 1 0 0 0 2 0 1 0 0 2 0 1 1
Mac 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
01234Jun 14Jun 11Jun 8Jun 5Jun 2May 30May 27May 24May 21May 18May 15May 12May 9May 6May 3Apr 30Jun 14 Linux: 0 Mac: 0 Windows: 0Jun 13 Linux: 0 Mac: 0 Windows: 0Jun 12 Linux: 0 Mac: 0 Windows: 0Jun 11 Linux: 0 Mac: 1 Windows: 0Jun 10 Linux: 0 Mac: 0 Windows: 2Jun 9 Linux: 0 Mac: 0 Windows: 0Jun 8 Linux: 0 Mac: 0 Windows: 0Jun 7 Linux: 1 Mac: 1 Windows: 0Jun 6 Linux: 0 Mac: 0 Windows: 2Jun 5 Linux: 0 Mac: 0 Windows: 0Jun 4 Linux: 0 Mac: 0 Windows: 1Jun 3 Linux: 0 Mac: 1 Windows: 1Jun 2 Linux: 0 Mac: 0 Windows: 2Jun 1 Linux: 1 Mac: 1 Windows: 1May 31 Linux: 0 Mac: 0 Windows: 0May 30 Linux: 0 Mac: 0 Windows: 2May 29 Linux: 0 Mac: 0 Windows: 2May 28 Linux: 0 Mac: 0 Windows: 0May 27 Linux: 0 Mac: 0 Windows: 0May 26 Linux: 0 Mac: 0 Windows: 0May 25 Linux: 0 Mac: 0 Windows: 0May 24 Linux: 0 Mac: 0 Windows: 0May 23 Linux: 0 Mac: 0 Windows: 1May 22 Linux: 0 Mac: 0 Windows: 0May 21 Linux: 0 Mac: 0 Windows: 0May 20 Linux: 1 Mac: 0 Windows: 2May 19 Linux: 0 Mac: 0 Windows: 1May 18 Linux: 1 Mac: 0 Windows: 0May 17 Linux: 3 Mac: 1 Windows: 0May 16 Linux: 0 Mac: 0 Windows: 1May 15 Linux: 0 Mac: 0 Windows: 0May 14 Linux: 0 Mac: 0 Windows: 0May 13 Linux: 0 Mac: 0 Windows: 0May 12 Linux: 0 Mac: 0 Windows: 1May 11 Linux: 0 Mac: 0 Windows: 0May 10 Linux: 0 Mac: 0 Windows: 0May 9 Linux: 0 Mac: 0 Windows: 0May 8 Linux: 0 Mac: 0 Windows: 2May 7 Linux: 0 Mac: 0 Windows: 0May 6 Linux: 0 Mac: 0 Windows: 1May 5 Linux: 0 Mac: 0 Windows: 0May 4 Linux: 0 Mac: 0 Windows: 0May 3 Linux: 0 Mac: 0 Windows: 2May 2 Linux: 0 Mac: 0 Windows: 0May 1 Linux: 0 Mac: 0 Windows: 1Apr 30 Linux: 0 Mac: 0 Windows: 1Jun 14 Linux: 0 Mac: 0 Windows: 0Jun 13 Linux: 0 Mac: 0 Windows: 0Jun 12 Linux: 0 Mac: 0 Windows: 0Jun 11 Linux: 0 Mac: 1 Windows: 0Jun 10 Linux: 0 Mac: 0 Windows: 2Jun 9 Linux: 0 Mac: 0 Windows: 0Jun 8 Linux: 0 Mac: 0 Windows: 0Jun 7 Linux: 1 Mac: 1 Windows: 0Jun 6 Linux: 0 Mac: 0 Windows: 2Jun 5 Linux: 0 Mac: 0 Windows: 0Jun 4 Linux: 0 Mac: 0 Windows: 1Jun 3 Linux: 0 Mac: 1 Windows: 1Jun 2 Linux: 0 Mac: 0 Windows: 2Jun 1 Linux: 1 Mac: 1 Windows: 1May 31 Linux: 0 Mac: 0 Windows: 0May 30 Linux: 0 Mac: 0 Windows: 2May 29 Linux: 0 Mac: 0 Windows: 2May 28 Linux: 0 Mac: 0 Windows: 0May 27 Linux: 0 Mac: 0 Windows: 0May 26 Linux: 0 Mac: 0 Windows: 0May 25 Linux: 0 Mac: 0 Windows: 0May 24 Linux: 0 Mac: 0 Windows: 0May 23 Linux: 0 Mac: 0 Windows: 1May 22 Linux: 0 Mac: 0 Windows: 0May 21 Linux: 0 Mac: 0 Windows: 0May 20 Linux: 1 Mac: 0 Windows: 2May 19 Linux: 0 Mac: 0 Windows: 1May 18 Linux: 1 Mac: 0 Windows: 0May 17 Linux: 3 Mac: 1 Windows: 0May 16 Linux: 0 Mac: 0 Windows: 1May 15 Linux: 0 Mac: 0 Windows: 0May 14 Linux: 0 Mac: 0 Windows: 0May 13 Linux: 0 Mac: 0 Windows: 0May 12 Linux: 0 Mac: 0 Windows: 1May 11 Linux: 0 Mac: 0 Windows: 0May 10 Linux: 0 Mac: 0 Windows: 0May 9 Linux: 0 Mac: 0 Windows: 0May 8 Linux: 0 Mac: 0 Windows: 2May 7 Linux: 0 Mac: 0 Windows: 0May 6 Linux: 0 Mac: 0 Windows: 1May 5 Linux: 0 Mac: 0 Windows: 0May 4 Linux: 0 Mac: 0 Windows: 0May 3 Linux: 0 Mac: 0 Windows: 2May 2 Linux: 0 Mac: 0 Windows: 0May 1 Linux: 0 Mac: 0 Windows: 1Apr 30 Linux: 0 Mac: 0 Windows: 1Jun 14 Linux: 0 Mac: 0 Windows: 0Jun 13 Linux: 0 Mac: 0 Windows: 0Jun 12 Linux: 0 Mac: 0 Windows: 0Jun 11 Linux: 0 Mac: 1 Windows: 0Jun 10 Linux: 0 Mac: 0 Windows: 2Jun 9 Linux: 0 Mac: 0 Windows: 0Jun 8 Linux: 0 Mac: 0 Windows: 0Jun 7 Linux: 1 Mac: 1 Windows: 0Jun 6 Linux: 0 Mac: 0 Windows: 2Jun 5 Linux: 0 Mac: 0 Windows: 0Jun 4 Linux: 0 Mac: 0 Windows: 1Jun 3 Linux: 0 Mac: 1 Windows: 1Jun 2 Linux: 0 Mac: 0 Windows: 2Jun 1 Linux: 1 Mac: 1 Windows: 1May 31 Linux: 0 Mac: 0 Windows: 0May 30 Linux: 0 Mac: 0 Windows: 2May 29 Linux: 0 Mac: 0 Windows: 2May 28 Linux: 0 Mac: 0 Windows: 0May 27 Linux: 0 Mac: 0 Windows: 0May 26 Linux: 0 Mac: 0 Windows: 0May 25 Linux: 0 Mac: 0 Windows: 0May 24 Linux: 0 Mac: 0 Windows: 0May 23 Linux: 0 Mac: 0 Windows: 1May 22 Linux: 0 Mac: 0 Windows: 0May 21 Linux: 0 Mac: 0 Windows: 0May 20 Linux: 1 Mac: 0 Windows: 2May 19 Linux: 0 Mac: 0 Windows: 1May 18 Linux: 1 Mac: 0 Windows: 0May 17 Linux: 3 Mac: 1 Windows: 0May 16 Linux: 0 Mac: 0 Windows: 1May 15 Linux: 0 Mac: 0 Windows: 0May 14 Linux: 0 Mac: 0 Windows: 0May 13 Linux: 0 Mac: 0 Windows: 0May 12 Linux: 0 Mac: 0 Windows: 1May 11 Linux: 0 Mac: 0 Windows: 0May 10 Linux: 0 Mac: 0 Windows: 0May 9 Linux: 0 Mac: 0 Windows: 0May 8 Linux: 0 Mac: 0 Windows: 2May 7 Linux: 0 Mac: 0 Windows: 0May 6 Linux: 0 Mac: 0 Windows: 1May 5 Linux: 0 Mac: 0 Windows: 0May 4 Linux: 0 Mac: 0 Windows: 0May 3 Linux: 0 Mac: 0 Windows: 2May 2 Linux: 0 Mac: 0 Windows: 0May 1 Linux: 0 Mac: 0 Windows: 1Apr 30 Linux: 0 Mac: 0 Windows: 1

Readme

Source
raw.​githubusercontent.​com

sublime-request

Make HTTP requests from Sublime Text.

Attach to the request command via your keyboard shortcuts or add a custom command pallete to hook into.

Getting started

Installation

This package is available under Request inside of Package Control, a Sublime Text plugin that allows for easy management of other plugins.

If you prefer the manual route, you can install the script via the following command in the Sublime Text terminal (ctrl+`) which utilizes git clone.

import os; path=sublime.packages_path(); (os.makedirs(path) if not os.path.exists(path) else None); window.run_command('exec', {'cmd': ['git', 'clone', 'https://github.com/twolfson/sublime-request', 'request'], 'working_dir': path})

Packages can be uninstalled via “Package Control: Remove Package” via the command pallete, ctrl+shift+p on Windows/Linux, command+shift+p on Mac.

Working with the plugin

By default, no keyboards shortcuts or commands are added to the command pallete.

You are left to add in your own custom features since typing out HTTP parameters every time is tedious.

To add your own custom keyboard shortcut:

  1. Open the command pallete, ctrl+shift+p on Windows/Linux, command+shift+p on Mac
  2. Navigate to “Preferences: Key Bindings - User”
  3. Inside of the top level [], add the following code
{
  "keys": ["alt+x"],
  "command": "request",
  "args": {
    "open_args": ["http://google.com/"],
    "save_to_clipboard": true
  }
}

You now have alt+x bound to download http://google.com/ to your clipboard.

Documentation

sublime-request is written on top of Python's urllib2 library (urllib in Sublime Text 3). We accept the following parameters:

  • open_args - List of arguments to pass to urllib2.urlopen/urllib.request.urlopen
  • open_kwargs - Dictionary of keyword arguments to pass to urllib2.urlopen/urllib.request.urlopen
  • read_args - List of arguments to pass to request.read
  • read_kwargs - Dictionary of keyword arguments to pass to request.read
  • save_to_clipboard - Copies result from read to clipboard

I don't know Python

This is a fact of life. Rather than creating a meta language to be just as simple, I will show you some commmon examples to draw from.

Using open “js {"open_args”: [url, data, timeout]}

// Make GET request to google.com // url = http://google.com/ {“open_args”: [“http://google.com/”]}

// Make POST request to google.com. Switches to POST when data is included // url = http://google.com/, data = “some=data” {“open_args”: [“http://google.com”, “some=data”]}

**Using read**
```js
{"read_args": [buffer_length]}

// Read all of response from request
// buffer_length = null (None in Python)
{"open_args": ["http://google.com/"]}

// Read first 100 bytes of response
// buffer_length = 100
{"open_args": ["http://google.com"], "read_args": [100]}

Examples

Ping a server

Ping a server via a key binding (requests http://localhost:3000/ when alt+x is pressed.

{
  "keys": ["alt+x"],
  "command": "request",
  "args": {
    "open_args": ["http://localhost:3000/"]
  }
}

Grab some Lorem Ipsum

Copy the first 100 characters of Lorem Ipsum to your clipboard via a key binding, alt+x.

{
  "keys": ["alt+x"],
  "command": "request",
  "args": {
    "open_args": ["http://loripsum.net/api/plaintext"],
    "read_args": [100],
    "save_to_clipboard": true
  }
}

FAQ

I want to see the results of my request.

Sublime Text comes default with an exec command which runs CLI commands in a panel. There are no official docs to my knowledge but you can find the source code via Command Pallete -> Browse Packages -> Default/exec.py@class ExecCommand.

Here is a key binding that runs curl to http://google.com/.

{
  "keys": ["alt+x"],
  "command": "exec",
  "args": {
    "cmd": ["curl", "http://google.com/"]
  }
}
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   219  100   219    0     0   2565      0 --:--:-- --:--:-- --:--:--  5918
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
[Finished in 0.1s]

Donating

Support this project and others by twolfson via gittip.

Support via Gittip

License

Copyright © 2013 Todd Wolfson

Licensed under the MIT license.