# mocked-fetch

> mock fetch api's for quicker app development

Latest version **1.1.1** (published 2022-11-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install mocked-fetch
pnpm add mocked-fetch
yarn add mocked-fetch
bun add mocked-fetch
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2022-11-26 |
| First published | 2022-10-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | SkillRazr |
| Maintainers | skillrazr |
| Keywords | mock, apis, local, mock, data |

## Links

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

## Dependencies (1)

- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.1

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2022-11-26
- 1.1.0 — 2022-11-26
- 1.0.2 — 2022-11-01
- 1.0.1 — 2022-10-26
- 1.0.0 — 2022-10-26

## README

# mocked-fetch [![NPM version](https://img.shields.io/npm/v/mocked-fetch.svg?style=flat)](https://www.npmjs.com/package/mocked-fetch) [![NPM monthly downloads](https://img.shields.io/npm/dm/mocked-fetch.svg?style=flat)](https://npmjs.org/package/mocked-fetch) [![NPM total downloads](https://img.shields.io/npm/dt/mocked-fetch.svg?style=flat)](https://npmjs.org/package/mocked-fetch)
fetch mocked for better development

mocked-fetch mocks the **fetch** API on browser and node. It helps you make GET, PUT, POST, DELETE calls to get resources without making any network calls. It serves data from a local file. 

Start writing your code using mockedFetch and in production build just replace it with fetch and the API endpoint. 

## Quick Start 
Install mocked-fetch 

```bash
npm install mocked-fetch
```

Get Todos using mocked-fetch 

```js 
   import { mockedFetch } from 'mocked-fetch'; 

    
    async function awaitTodos () {
        const data = await mockedFetch('https://skillrazr.com/todos'); 
        const finalData = await data.json();
        console.log('data todos', finalData);
    }

    awaitTodos();
```
Get a todo by given todoId :- 
    
```js
    async function awaitTodo (todoId) {
        const data = await mockedFetch(`https://skillrazr.com/todos/${todoId}`); 
        const finalData = await data.json();
        console.log('got todo', finalData);
    }
```

Update a todo :-
```js 
   mockedFetch('https://skillrazr.com/todos/1', {
    method: 'PUT',
    body: JSON.stringify({
        title: 'Write test cases',
        completed: false,
    }),
    headers: {
        "Content-type": 'application/json; charset=UTF-8',
    }
  });
  ```
Create a new todo :-

```js 
mockedFetch('https://skillrazr.com/todos/', {
  method: 'POST',
  body: JSON.stringify({
    title: 'Create shopping list',
    completed: false,
  }),
  headers: {
    "Content-type": 'application/json; charset=UTF-8',
  }
  })
  .then((response) => response.json())
  .then((json) => console.log('add new todo response', json));
  ```
    
  Delete a todo :- 
  ```js 
  mockedFetch('https://skillrazr.com/todos/1', {
    method: 'DELETE',
    headers: {
        "Content-type": 'application/json; charset=UTF-8',
    }
  })
  .then((response) => response.json())
  .then((json) => console.log('deleted todo response', json));
  ```
  
  ## Running tests ( Jasmine integration pending) 
  ```bash
npm run test
```

## Contributions are open (Raise PRs)

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