# railgun.Request

The requests module contains one of the most used utilities throughout Railgun. Request Builders
are created by the proxy and sequencer, and are used extensively by the spider, amongst other
things.  The request builder class, available via `railgun.Request` is really just a wrapper
around a [request options object](https://github.com/request/request#requestoptions-callback).
Request builders make certain fields mandatory and take the `headers` option out a level to make
it more accessable.

Example:

```js
const railgun = require('railgun')

let req = new railgun.Request('GET', 'https://site.horse', {
  // We can pass an object containing headers as the third argument.
  'User-Agent': 'Railgun User'
}, {
  // Options other than the headers can be included as the fourth argument.
  proxy: 'http://localhost:9001'
})

// Add another header to the request
req.headers['Accept'] = 'text/html'

// Add a new option to the request
req.options.gzip = false

req.send()
.then((response) => console.log(response.body.toString('utf8')))
```

## Methods

### railgun.Request#constructor

The request builder constructor can accept two (2) to four (4) arguments. In order, they are

1. The HTTP method for the request (e.g. GET, POST, PUT, ...)
2. The URL for the resource to request
3. A headers object to supply the request with
4. An object containing other options to pass to the [request](https://github.com/request/request) library call.

Headers and options will both be defaulted to an empty object `{}`.

### railgun.Request#finalize

Request#finalize gets an options object by reorganizing the builder's contents in case you need to
use the request library directly for some reason.

### railgun.Request#clone

Request#clone copies the contents of the request builder into a new builder with all of the
same information.

### railgun.Request#send

Request#send finalizes the request builder into an options object and sends the request.
It returns a promise that resolves to the response object received from the request library
directly, with the body included in it.
