mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Add more examples
This commit is contained in:
parent
5d53f277ee
commit
680c5a456f
3 changed files with 47 additions and 0 deletions
|
@ -70,3 +70,14 @@
|
|||
* Uses `get` requests
|
||||
* Uses `stream_body` mode
|
||||
* Download file without using the memory
|
||||
|
||||
* [Microsoft graph](microsoft_graph.rb)
|
||||
* Basic Auth
|
||||
* Uses `post` requests
|
||||
* Uses multipart
|
||||
|
||||
* [Multipart](multipart.rb)
|
||||
* Multipart data upload _(with and without file)_
|
||||
|
||||
* [Uploading File](body_stream.rb)
|
||||
* Uses `body_stream` to upload file
|
||||
|
|
14
examples/body_stream.rb
Normal file
14
examples/body_stream.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
# To upload file to a server use :body_stream
|
||||
|
||||
HTTParty.put(
|
||||
'http://localhost:3000/train',
|
||||
body_stream: File.open('sample_configs/config_train_server_md.yml', 'r')
|
||||
)
|
||||
|
||||
|
||||
# Actually, it works with any IO object
|
||||
|
||||
HTTParty.put(
|
||||
'http://localhost:3000/train',
|
||||
body_stream: StringIO.new('foo')
|
||||
)
|
22
examples/multipart.rb
Normal file
22
examples/multipart.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# If you are uploading file in params, multipart will used as content-type automatically
|
||||
|
||||
HTTParty.post(
|
||||
'http://localhost:3000/user',
|
||||
body: {
|
||||
name: 'Foo Bar',
|
||||
email: 'example@email.com',
|
||||
avatar: File.open('/full/path/to/avatar.jpg')
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# However, you can force it yourself
|
||||
|
||||
HTTParty.post(
|
||||
'http://localhost:3000/user',
|
||||
multipart: true,
|
||||
body: {
|
||||
name: 'Foo Bar',
|
||||
email: 'example@email.com'
|
||||
}
|
||||
)
|
Loading…
Add table
Reference in a new issue