Skip to content

Commit d905c1b

Browse files
author
William Tsai
committed
Update Readme
1 parent b676868 commit d905c1b

1 file changed

Lines changed: 45 additions & 13 deletions

File tree

README.md

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# JsonRequester
22

3-
`JsonRequester` is a lightweight wrapper around Faraday for sending JSON, form-encoded, and multipart HTTP requests.
3+
`JsonRequester` is a lightweight wrapper around Faraday for sending
4+
JSON, form-encoded, and multipart HTTP requests.
45

56
## Requirements
67

@@ -32,7 +33,11 @@ gem install json_requester -v '~> 1.0'
3233
```ruby
3334
host = 'http://httpbingo.org'
3435

35-
requester = JsonRequester.new(host, timeout: 120, user_agent: 'My Agent 1.2')
36+
requester = JsonRequester.new(
37+
host,
38+
timeout: 120,
39+
user_agent: 'My Agent 1.2'
40+
)
3641
```
3742

3843
Available initialization options:
@@ -57,7 +62,15 @@ params = {
5762
key_2: 'value_2'
5863
}
5964

60-
response = requester.http_send(:post, path, params, headers, sort_params: true, content_type_charset: 'utf-8', need_response_header: true)
65+
response = requester.http_send(
66+
:post,
67+
path,
68+
params,
69+
headers,
70+
sort_params: true,
71+
content_type_charset: 'utf-8',
72+
need_response_header: true
73+
)
6174

6275
puts response['status']
6376
puts response['body']
@@ -76,7 +89,14 @@ params = {
7689
key_2: 'value_2'
7790
}
7891

79-
form_response = requester.form_send(:post, path, params, headers, sort_params: true, need_response_header: true)
92+
form_response = requester.form_send(
93+
:post,
94+
path,
95+
params,
96+
headers,
97+
sort_params: true,
98+
need_response_header: true
99+
)
80100
```
81101

82102
### Send multipart requests
@@ -91,7 +111,12 @@ upload_params = {
91111
description: 'File upload example'
92112
}
93113

94-
upload_response = multipart_requester.multipart_form_send(:post, '/upload_path', upload_params, { 'Authorization' => 'Bearer token' })
114+
upload_response = multipart_requester.multipart_form_send(
115+
:post,
116+
'/upload_path',
117+
upload_params,
118+
{ 'Authorization' => 'Bearer token' }
119+
)
95120
```
96121

97122
## Request Methods
@@ -102,21 +127,28 @@ upload_response = multipart_requester.multipart_form_send(:post, '/upload_path',
102127

103128
### Method overview
104129

105-
- `http_send`: uses query params for `:get`, and sends a JSON body for other HTTP methods
130+
- `http_send`: uses query params for `:get`, and sends a JSON body for
131+
other HTTP methods
106132
- `form_send`: sends requests as `application/x-www-form-urlencoded`
107-
- `multipart_form_send`: sends multipart form data, typically for file uploads
133+
- `multipart_form_send`: sends multipart form data, typically for file
134+
uploads
108135

109-
Supported HTTP methods include:
110-
111-
- `sort_params`: controls whether query parameters are sorted before sending, default is `true`
112-
- `content_type_charset`: used by `http_send` for JSON requests, default is `'utf-8'`
113-
- `need_response_header`: when set to `true`, includes response headers in the returned result
136+
`http_send`, `form_send`, and `multipart_form_send` accept HTTP verbs
137+
such as:
114138

115139
- `:get`
116140
- `:post`
117141
- `:put`
118142
- `:delete`
119143

120-
### Common optionsSecurity
144+
### Common options
145+
146+
- `sort_params`: controls whether query parameters are sorted before sending, default is `true`
147+
- `content_type_charset`: used by `http_send` for JSON requests,
148+
default is `'utf-8'`
149+
- `need_response_header`: when set to `true`, includes response
150+
headers in the returned result
151+
152+
## Security
121153

122154
Please see [SECURITY.md](SECURITY.md) for vulnerability reporting instructions.

0 commit comments

Comments
 (0)