Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/lete114/body-data

一个轻量、小巧的Node.js模块,用于检索 GET 或 POST 请求数据 | A lightweight, small Node.js module for retrieving GET or POST request data
https://github.com/lete114/body-data

Last synced: 14 days ago
JSON representation

一个轻量、小巧的Node.js模块,用于检索 GET 或 POST 请求数据 | A lightweight, small Node.js module for retrieving GET or POST request data

Awesome Lists containing this project

README

        


语言:
中文
English

Body-Data


一个轻量、小巧的Node.js模块,用于检索 GET 或 POST 请求数据


Version
dev
MIT License

## 安装

```bash
npm install body-data --save
```

## 快速开始

```js
// client
const script = document.createElement('script')
script.src = 'https://cdn.jsdelivr.net/npm/axios/dist/axios.js'
document.head.append(script)

const url = 'http://127.0.0.1:6870'
axios.get(url, { params: { name: 'Lete', age: 18 } })
axios.post(url, { name: 'Lete', age: 18 })

// server
const bodyData = require('body-data')
const http = require('http')

const server = http.createServer(async (req, res) => {
res.setHeader('Content-Type', 'application/json; charset:utf-8;')
const data = await bodyData(req)
res.end(JSON.stringify(data)) // output: { name: 'Lete', age: 18 }
})

server.listen(6870)
```