0.0.2 • Published 1 year ago

elysia-xml v0.0.2

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

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

KeyTypeDefaultDescription
builder?XmlBuilderOptionsOptions to configure XML builder
parser?X2jOptionsOptions 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?booleanfalseDon't look at the accept header to serialize?
transformResponse?(value: any) => anyHandler to transform response
as?LifeCycleType"scoped"Option to specify type of hooks

Thanks