Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/qiwi/cookiemonster

Stateless fake API based on cookie processing
https://github.com/qiwi/cookiemonster

Last synced: 4 days ago
JSON representation

Stateless fake API based on cookie processing

Awesome Lists containing this project

README

        

# qookiemonster
[![CI](https://github.com/qiwi/cookiemonster/actions/workflows/ci.yaml/badge.svg?branch=master&event=push)](https://github.com/qiwi/cookiemonster/actions/workflows/ci.yaml)
[![Maintainability](https://api.codeclimate.com/v1/badges/01b67bf5bc60a67df296/maintainability)](https://codeclimate.com/github/qiwi/cookiemonster/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/01b67bf5bc60a67df296/test_coverage)](https://codeclimate.com/github/qiwi/cookiemonster/test_coverage)
> Stateless fake API based on cookie processing

## Usage
On server side:
```ts
//...
import {cookiemonster} from '@qiwi/cookiemonster'

const app = express()

app.use(cookieParser())
app.use(bodyParser.json())
app.use(cookiemonster())

app.listen(8080)
```

On client:

```ts
import {formatScenario} from '@qiwi/cookiemonster'

const data = formatScenario({
steps: [
{res: {code: 200, body: {foo: 'bar'}}}
]
})

document.cookie = `Cookiemonster=${data}`

const result = await fetch('http://localhost:8080', {credentials: 'include'})
const json = await result.json() // {foo: 'bar'}
```

## Refs
* [mock-server/mockserver](https://github.com/mock-server/mockserver)

## License
[MIT](./LICENSE)