DEV Community

Andrew Petersen
Andrew Petersen

Posted on

3 1

SharePoint Rest API Formatter

Before stumbling across the article, Userscripts Are Fun And Are Still Very Much Relevant, I had never heard of Userscripts. They are pretty useful; kind of like a bare bones browser extension.

The first thing I created was a helper to format and syntax highlight the XML that comes back when navigating to a SharePoint REST endpoint in Chrome or Edge.

Userscript automatically kicks in on all REST API urls
End Result

Without it, it'd look like this
Raw XML Response

Previous Solutions/Attempts

  • I've installed Chrome Extensions to automatically format/syntax highlight XML, but they perform mediocre at best
  • I've experimented with Chrome Extensions to automatically set the request headers to application/json, but that inevitably causes problems when I forget to turn it off, and sometimes I prefer the ATOM/XML response because it shows you what child properties you can expand on.

Goals

  1. Format and syntax highlight the XML response
  2. Provide a toggle to switch between XML or JSON response

Install Steps

  1. Install the ViolentMonkey Chrome Extension
    • This is what manages all your Userscripts.
    • It's a weird name, but it has worked great so far.
  2. Add a new User Script from URL
    • Open the ViolentMonkey extension Dashboard,
    • Then click "New Script from Url" and paste in the following url.
    • It's the raw url to this Gist, which is the result of my efforts. Definitely take a look at the code if you're interested.
https://gist.githubusercontent.com/DroopyTersen/7234e172ba004a5689910f05822a1b95/raw/a0a7e03c47daa55ef7a34ac433f6231fdb0e9bb5/REST%2520API%2520Formatter%2520Userscript

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay