Comments (3)
By default, Elysia will parse the body with content-type
of text/plain
and application/json
and assign to body
.
Then you can get body
from Context.body
:
import { Elysia } from 'elysia'
const app = new Elysia()
.post("/add", ({ body }) => {
console.log(body)
})
.listen(8080)
If you want to support more content-type
, you can use onParse
:
app
.onParse((request, contentType) => {
if (contentType === 'application/custom-type')
return request.text()
})
The returned value will be assigned to body
in handler.
from elysia.
why is it still error even though it feels right
when I test with postman
root@minto-Lenovo-V145-14AST:/home/minto/belajar/elysyaPro/elyapp/manelysia# bun run dev
$ bun run --hot src/index.ts
🦊 Elysia is running at 0.0.0.0:3000
1 | import { Elysia } from 'elysia'
2 |
3 | const app = new Elysia()
4 | .get('/', () => 'Hello 1231')
5 | .post("/add",()=>({body})=>{
6 | console.log(body)
^
TypeError: Right side of assignment cannot be destructured
at /home/minto/belajar/elysyaPro/elyapp/manelysia/src/index.ts:6:8
at handle (/home/minto/belajar/elysyaPro/elyapp/manelysia/node_modules/elysia/build/es/index.js:229:17)
from elysia.
SOLVED THANKS
from elysia.
Related Issues (20)
- `mapResponse` is completely ignored HOT 2
- Please Export Typebox Types HOT 1
- staticPlugin didn't supply chinese path
- Context object not correctly passed to handler HOT 1
- Cannot use Plain Typebox Types for Schema
- Normalize not working for children instances
- Merge group schema with route schema HOT 1
- I get code: "ERR_INVALID_ARG_TYPE" when I run my Elysia app. HOT 1
- Unable to Unit Test WebSocket HOT 9
- Cookies are getting signed but not unsigned HOT 1
- onError handler isn't getting called during INVALID_COOKIE_SIGNATURE HOT 1
- Domain is not set when using cookie.remove() HOT 3
- Strange "error()" behavior with response schema
- headers(header: Context['set']['headers'] | undefined) not work when no aot
- `NotFoundError` doesn't call `onAfterResponse` hook with `aot: true`
- Add `response` object in route handlers arguments as an alternative to `set` and `cookie`
- Bearer plugin doesn't work on Elysia 1.1.0-rc.9 HOT 1
- Semver not followed correctly HOT 2
- [Sucrose] unexpected isContextPassToFunction error HOT 4
- Type error with global `app.derive` followed by `onError` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elysia.