What is Layout Service Testing?

The Layout Service is what powers Sitecore JSS and provides the data about a given URL/page request in the form of a JSON object. If you've heard of the Sitecore Web API before, this is rather similar in execution, if more specialised in scope.

Below is an example of the JSON object returned for a given page:

JSON snippet

Generally speaking, we would never actively call the Layout Service directly, but sometimes it's good for testing purposes to be able to get a raw data dump to ensure data is actually being given in the correct format (or at all) before looking elsewhere.

Enjoying this article? Sign up to our newsletter

How to use it for testing

The endpoint that powers the layout service sits at the URL of: {siteName}/sitecore/api/layout/render/jss

This requires two additional pieces of information in query string form to supply data:

  1. The path of the item requested. For example a sitecore/content/home/sample would use the path /sample
  2. The GUID of the API key. This is a value that is configured in Sitecore when first setting up JSS

With these in mind, the URL to request the data can be built like this, {sitename}/sitecore/api/layout/render/jss/?item=sample&sc_apikey={00000000-0000-0000-0000-000000000000}

At Codehouse we continually work on exciting design and build Sitecore projects. Our development team use best practices to build robust and engaging Sitecore websites.