File: README.md

package info (click to toggle)
ruby-http-form-data 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 192 kB
  • sloc: ruby: 826; makefile: 3
file content (97 lines) | stat: -rw-r--r-- 2,849 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# HTTP::FormData

[![Gem Version](https://badge.fury.io/rb/http-form_data.svg)](http://rubygems.org/gems/http-form_data)
[![Build Status](https://secure.travis-ci.org/httprb/form_data.svg?branch=master)](http://travis-ci.org/httprb/form_data)
[![Code Climate](https://codeclimate.com/github/httprb/form_data.svg)](https://codeclimate.com/github/httprb/form_data)
[![Coverage Status](https://coveralls.io/repos/httprb/form_data.rb/badge.svg?branch=master)](https://coveralls.io/r/httprb/form_data.rb)

Utility-belt to build form data request bodies.


## Installation

Add this line to your application's Gemfile:

```ruby
gem 'http-form_data'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install http-form_data


## Usage

``` ruby
require "http/form_data"

form = HTTP::FormData.create({
  :username     => "ixti",
  :avatar_file  => HTTP::FormData::File.new("/home/ixti/avatar.png")
})

# Assuming socket is an open socket to some HTTP server
socket << "POST /some-url HTTP/1.1\r\n"
socket << "Host: example.com\r\n"
socket << "Content-Type: #{form.content_type}\r\n"
socket << "Content-Length: #{form.content_length}\r\n"
socket << "\r\n"
socket << form.to_s
```

It's also possible to create a non-file part with Content-Type:

``` ruby
form = HTTP::FormData.create({
  :username     => HTTP::FormData::Part.new('{"a": 1}', content_type: 'application/json'),
  :avatar_file  => HTTP::FormData::File.new("/home/ixti/avatar.png")
})
```

## Supported Ruby Versions

This library aims to support and is [tested against][ci] the following Ruby
versions:

* Ruby 2.1.x
* Ruby 2.2.x
* Ruby 2.3.x
* Ruby 2.4.x
* JRuby 9.1.x.x

If something doesn't work on one of these versions, it's a bug.

This library may inadvertently work (or seem to work) on other Ruby versions,
however support will only be provided for the versions listed above.

If you would like this library to support another Ruby version or
implementation, you may volunteer to be a maintainer. Being a maintainer
entails making sure all tests run and pass on that implementation. When
something breaks on your implementation, you will be responsible for providing
patches in a timely fashion. If critical issues for a particular implementation
exist at the time of a major release, support for that Ruby version may be
dropped.


## Contributing

1. Fork it ( https://github.com/httprb/form_data.rb/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request


## Copyright

Copyright (c) 2015-2017 Alexey V Zapparov.
See [LICENSE.txt][license] for further details.


[ci]:       http://travis-ci.org/httprb/form_data.rb
[license]:  https://github.com/httprb/form_data.rb/blob/master/LICENSE.txt