Skip to content

Commit b4353fb

Browse files
docs: more examples
1 parent 3d9255d commit b4353fb

File tree

11 files changed

+72
-22
lines changed

11 files changed

+72
-22
lines changed

spec/examples/basic_get.http

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ user-agent: neovim
44

55
### get statement for localhost
66
GET localhost:9999
7+
8+
### multi-line url
9+
// reference: https://www.jetbrains.com/help/idea/exploring-http-syntax.html#break-long-requests-into-several-lines
10+
// You can span url to multiple lines by adding whitespace indents
11+
GET http://example.com:8080
12+
/api
13+
/html
14+
/get
15+
?id=123
16+
&value=content

spec/examples/examples_spec.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ end
1313

1414
describe("multi-line-url", function()
1515
it("line breaks should be ignored", function()
16-
local source = open("spec/examples/multi_line_url.http")
16+
local source = open("spec/examples/basic_get.http")
1717
local _, tree = utils.ts_parse_source(source)
18-
local req_node = assert(tree:root():child(0))
18+
local req_node = assert(tree:root():child(2))
1919
local req = parser.parse(req_node, source)
2020
assert.not_nil(req)
2121
---@cast req rest.Request
@@ -107,7 +107,7 @@ end)
107107
describe("builtin request hooks", function()
108108
describe("set_content_type", function()
109109
it("with external body", function()
110-
local source = open("spec/examples/post_with_external_body.http")
110+
local source = open("spec/examples/request_body/external_body.http")
111111
local _, tree = utils.ts_parse_source(source)
112112
local req_node = assert(tree:root():child(0))
113113
local req = assert(parser.parse(req_node, source))

spec/examples/multi_line_url.http

Lines changed: 0 additions & 9 deletions
This file was deleted.

spec/examples/post_with_external_body.http

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### External body
2+
POST https://example.com:8080/api/html/post
3+
# rest.nvim can guess and fill the Content-Type header from file path
4+
5+
< ./input.json
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# form-urlencoded type is recognized with `Content-Type` header
2+
3+
### form-urlencoded
4+
POST https://ijhttp-examples.jetbrains.com/post
5+
Content-Type: application/x-www-form-urlencoded
6+
7+
key1=value1&key2=value2&key3=value3&key4=value4&key5=value5
8+
9+
### form-urlencoded (multiline)
10+
# you can put some whitespaces in urlencoded form
11+
# rest.nvim will recognize whitespaces and remove them before request
12+
POST https://ijhttp-examples.jetbrains.com/post
13+
Content-Type: application/x-www-form-urlencoded
14+
15+
key1 = value1 &
16+
key2 = value2 &
17+
key3 = value3 &
18+
key4 = value4 &
19+
key5 = value5
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# all bodies including json are treated as raw body
2+
3+
### json body
4+
# request body starting with `{\n` will have json syntax injection via tree-sitter
5+
# rest.nvim provides opt-out json validation feature
6+
POST https://example.com HTTP/1.1
7+
Content-Type: application/json
8+
9+
{
10+
"foo": 123
11+
}
12+
13+
### xml body
14+
# request body starting with `<.*` will have xml syntax injection via tree-sitter
15+
# rest.nvim provides opt-out xml validation feature
16+
POST https://example.com HTTP/1.1
17+
Content-Type: application/xml
18+
19+
<?xml version="1.0" encoding="utf-8"?>
20+
<Request>
21+
<Login>login</Login>
22+
<Password>password</Password>
23+
</Request>
24+
25+
### raw body
26+
# all other bodies will be treated as raw body type
27+
POST https://example.com HTTP/1.1
28+
29+
Hello world!

spec/examples/variables/dynamic_vars.http

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
### dynamic variables
12
POST https://reqres.in/api/users
23
Content-Type: application/json
34

spec/examples/variables/prompt_variables.http

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### basic get statement
1+
### prompt variables
22

33
# Basic syntax of prompt variable:
44

0 commit comments

Comments
 (0)