1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Add more examples

This commit is contained in:
 TheSmartnik 2018-10-31 07:56:06 +03:00
parent 5d53f277ee
commit 680c5a456f
3 changed files with 47 additions and 0 deletions

View file

@ -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
View 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
View 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'
}
)