Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

elysia-xml

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elysia-xml

The library for elysia which allows you to work with XML

latest
npmnpm
Version
0.0.2
Version published
Weekly downloads
16
-72.41%
Maintainers
1
Weekly downloads
 
Created
Source

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

  • fast-xml-parser - this library use it under the hood

Keywords

elysia

FAQs

Package last updated on 12 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts