website/docs/data.md

2.0 KiB

Handy-Http Data

DDoc Reference

The Data component provides support for some data formats that are common in web servers.

JSON

Support for reading and writing JSON is provided via the ASDF library. Two methods are provided to help with JSON I/O for HTTP requests:

  • readJsonBodyAs for deserializing a JSON request body into some type.
  • writeJsonBody for serializing some data into a JSON response body.

Multipart Formdata

The multipart.d module provides support for reading HTTP request bodies defined as multipart/form-data. The main function to use here is readBodyAsMultipartFormData, which takes in a reference to a ServerHttpRequest, and returns a MultipartFormData struct containing the parsed contents.

The parsed form data simply contains a list of elements of type MultipartElement, and you can read the underlying data from the element's content attribute.

In practice, multipart formdata is most often used when one would like to send multiple types of data to an API at once, such as when a user is submitting a form that includes basic fields as well as file uploads.

XML

Support for XML is provided via the DXML library. Two methods are provided to help with XML I/O for HTTP requests:

  • readXMLBody for reading a request body as an XML DOMEntity.
  • writeXMLBody for writing a response body by supplying a delegate function that builds the XML tag tree that you'd like to write.