Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Response Parsers

Patrick Rodgers edited this page Jan 3, 2017 · 5 revisions

Under the hood the library makes use of parser classes to handle converting the response object returned by fetch into the result. Each of the methods of the Queryable (get, post, patch, delete) also takes an optional parser argument. It is highly likely you will not need to write a custom parser, but this article outlines the process if you do.

What's Included

The default parser, ODataDefaultParser, is used for all requests by default (except a few special cases). It will check the response for an error and then parse the response body as JSON. You can use it directly by importing it, but there is no need as it is the default. But if you wanted to it would look like the below and match the result you get by passing nothing.

import { ODataDefaultParser } from "sp-pnp-js";

pnp.sp.web.lists.getByTitle("rapidadd").items.get(new ODataDefaultParser()).then(result => {
   console.log(result);
});

You can use the ODataRaw parser to return the raw results of requests, which can help with debugging:

import { ODataRaw } from "sp-pnp-js";

pnp.sp.web.lists.getByTitle("rapidadd").items.get(ODataRaw).then(result => {
   console.log(result);
});

There are also parsers to handle files but you shouldn't need to use them directly, these are: TextFileParser, BlobFileParser, BufferFileParser, JSONFileParser. See the Working with Files article for more details on manipulating files.

The final set of parsers are made to work with the getAs method. These allow you to merge the result data into one of the objects, such as list.

ODataRaw,
ODataValue,
ODataEntity,
ODataEntityArray,
,
,
,
Clone this wiki locally