0.0.2 • Published 1 year ago
elysia-xml v0.0.2
elysia-xml
The library for elysia which allows you to work with XML
Installation
bun install elysia-xml
Usage
import Elysia from "elysia"
import { xml } from "elysia-xml"
new Elysia()
.use(xml())
.post("/", ({ body }) => {
// body is object of parsed XML if content-type header the specified Content-Type
// if accept header contains the specified Content-Type
// this response will become a XML string with first content-type from array,
// and if not, it will remain JSON
return {
some: "values",
and: true,
keys: 228,
}
})
.listen(3000)
Use xml
decorator
You can also use the xml method to force xml to be returned.
new Elysia().use(xml()).post("/", ({ xml }) =>
xml({
some: "values",
and: true,
keys: 228,
})
);
This method return Response
Output
<some>values</some>
<and>true</and>
<keys>228</keys>
Options
Key | Type | Default | Description |
---|---|---|---|
builder? | XmlBuilderOptions | Options to configure XML builder | |
parser? | X2jOptions | Options to configure XML parser | |
contentTypes? | string[] | "text/xml", "application/xml", "application/rss+xml" | An array of content-types that need to be serialized/deserialized |
force? | boolean | false | Don't look at the accept header to serialize? |
transformResponse? | (value: any) => any | Handler to transform response | |
as? | LifeCycleType | "scoped" | Option to specify type of hooks |
Thanks
- fast-xml-parser - this library use it under the hood