# multipartish

> Dead simple way of producing multipart/* messages

Latest version **0.1.1** (published 2017-02-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install multipartish
pnpm add multipartish
yarn add multipartish
bun add multipartish
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-02-04 |
| First published | 2017-02-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Peter Hanula |
| Maintainers | miko3k |
| Keywords | multipart, multipart/mixed, browser, http, request |

## Links

- npm: https://www.npmjs.com/package/multipartish
- Repository: https://github.com/miko3k/multipartish
- Homepage: https://github.com/miko3k/multipartish#readme
- Issues: https://github.com/miko3k/multipartish/issues
- npm.io page: https://npm.io/package/multipartish

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2017-02-04
- 0.1.0 — 2017-02-04

## README

# multipartish

Dead simple way of producing `multipart/*` data. Works in browser, node, or anywhere else (hopefully), because it's super simple.

## Installation

```javascript
npm install multipartish --save
```

## Example

Hello world

```javascript
var MultiPartish = require('multipartish')

console.log(new MultiPartish().header("Content-Type", "text/plain").part("hello world").get())
```

This example shows how to [upload file to Google drive](https://developers.google.com/drive/v3/web/manage-uploads#multipart)

```javascript
// prepare data
var MultiPartish = require('multipartish')
var name = "My File"
var body = "text\n"

var m = new MultiPartish()
m.header("Content-Type", "application/json; charset=UTF-8")
m.part(JSON.stringify(name: name))
m.header("Content-Type", "text/plain")
m.part(body)

var body_data = m.get()
var contentType = m.contentType()

// upload
gapi.client.request({
   'path': 'https://www.googleapis.com/upload/drive/v3/files',
   'method': 'POST',
   'params': {'uploadType': 'multipart'},
   'headers': { 'Content-Type': contentType },
   'body': body_data
})
```


## Usage

### Constructor

Constructor accepts a single object as parameter, encapsulating the optional arguments. Only one key is currently defined:

* `boundary`: set boundary value, use is discouraged, but it makes writing unit tests possible

Examples:
```javascript
   var MultiPartish = require('multipartish')

   var a = new MultiPartish()
   var b = new MultiPartish({boundary: 'my-boundary'})
```

### Methods

#### get()

Returns the complete multipart message. Most important method! Returns `this`.

#### part(body)

Adds a part. Second most important method! Returns `this`.

#### header(value)

Specifies a header for following part, for example `.header("Content-Type: text/plain")`

#### header(name, value)

Specifies a header for following part, for example `.header('Content-Type', 'text/plain')`

Equavalent to:

```javascript
header(name + ": " + value)
```


#### contentType()

Returns `multipart/mixed; boundary=XXX`.

#### contentType(something)

Returns `multipart/something; boundary=XXX`. According to [RFC](https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html)
you can set `something` to: `mixed`, `alternative`, `digest` or `parallel`.

### Public properties

#### boundary

Boundary of multipart message. Consider this property read-only, if you feel you want to set this property,
you should use the contructor argument instead.

## Version history

0.1.0 - initial release
0.1.1 - fluent api support

---
_Source: https://npm.io/package/multipartish · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
