# @nayotta/mta-fetch

> fetch module

Latest version **1.2.1** (published 2021-12-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nayotta/mta-fetch
pnpm add @nayotta/mta-fetch
yarn add @nayotta/mta-fetch
bun add @nayotta/mta-fetch
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2021-12-29 |
| First published | 2021-10-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | nayotta.fe |
| Maintainers | goku-gaga, classlfz, linli_08 |
| Keywords | browser, fetch |

## Links

- npm: https://www.npmjs.com/package/@nayotta/mta-fetch
- Repository: https://github.com/nayotta/mta-fetch
- Homepage: https://github.com/nayotta/mta-fetch#readme
- Issues: https://github.com/nayotta/mta-fetch/issues
- npm.io page: https://npm.io/package/@nayotta/mta-fetch

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2021-12-29
- 1.2.0 — 2021-12-28
- 1.1.1 — 2021-10-15
- 1.1.0 — 2021-10-15
- 1.0.1 — 2021-10-15
- 1.0.0 — 2021-10-15

## README

# mta-fetch

[![Build & Lint & Test](https://github.com/nayotta/mta-fetch/actions/workflows/build.yml/badge.svg)](https://github.com/nayotta/mta-fetch/actions/workflows/build.yml)

> a simple browser fetch module.

## install

```sh
$ npm install @nayotta/mta-fetch --save
```

## example

```js
const MtaFetch = require('@nayotta/mta-fetch')

const mtaFetch = new MtaFetch({
	host: 'http://example.com',
	apis: {
		signin: {
			url: '/v1/signin',
			method: 'post',
			errMsgs: {
				200: 'signin success',
				401: 'unauthorization',
				500: 'sever error'
			}
		},
		getInfo: {
			url: '/v1/books/type/:id',
			method: 'get'
		}
	}
})

mtaFetch.send({
	type: 'signin',
	// default content-type is application/json
	// form-data can be set by format argument
	data: {
		username: 'username',
		password: 'password'
	}
}).then(res => {
	const { ok, status, errMsg, data } = res
	console.log(ok, status, errMsg, data)
})

mtaFetch.setToken('Bearer token')

mtaFetch.send({
	type: 'getInfo',
	urlParams: {
		id: 'info_id'
	},
	query: {
		search: 'keyword'
	},
	errMsg: {
		200: 'success',
		400: 'bad request',
		401: 'unauthorization',
		404: 'not found',
		500: 'server error'
	}
}).then(res => {
	const { ok, status, errMsg, data } = res
	console.log(ok, status, errMsg, data)
})
```

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