SliceZone (SliceMachine) data from Java

Hi,

We are looking to rebuild our current webshop to use Nuxt with slice machine. We saw some downsides about this approach because in one document we have linkedDocuments as well as a sliceZone. Also we want to enrich data from prismic using a multiple sources, to do this we want to use our current Java backend and move the request to prismic there.

The problem that we are facing is that the sliceZone component in vue made a query to prismic and until now we are not able to reproduce/replicate the response in Java. We don't know what kind of response is needed for nuxt to render the slicezones.

Can you give us some advice for using this approach? Is Slicezone supported in the JDK?

@nouha.chhih Can you please follow up on this topic?

Hey @juan.sanchez, @marcel.overbeek

I'm not sure I fully got your question so let me break it down and tell me if that help :slightly_smiling_face:

Regarding what you're trying to achieve, moving from some templating engine in Java to Nuxt.js + Slice Machine is definitely doable! Same goes for enriching data from Prismic in your Java backend.

One thing I would advise you to consider is to fully leverage Nuxt.js data fetching methods to perform the enrichment there. Sounds smoother to me than proxying request to Prismic through your backend, nonetheless, I suspect you may have things that you prefer to keep there, so that's up to you~

Also regarding Prismic data enrichment, I'm not sure if you're aware of that feature of not, but you can leverage Integration Fields, they can allow you to plug any catalog of yours to Prismic repositories.

Now to the issues you are facing. Not sure I fully got querying the Slice Zone in Java, but here are the basics: The Slice Zone is a part of your documents where you can compose with Slices, just like any fields in your document you can find it in the returned object, by default the default Slice Zone is at key body.

What happens with the Nuxt Slice Zone component is that it performs a fetch to get a document in Prismic, and then feeds the array of slices at key body to it. You can also directly supply an array of slices to the Slice Zone using the slices props. More on using Nuxt Slice Zone here.

About Slice Zone structure and its support in our Java Kit you might find handy the Javadoc here, the Fragment.Slice class and the ones implementing it might be what you're looking for. Here's a dummy representation of the JSON structure returned by the API of a Slice Zone:

[
  {
    slice_type: String,
    primary: Map<String,Fragment>
    items: Array<Map<String,Fragment>>
  }
  /* ... */
]

Voila! Hope that was helpful~

Again I'm really suggesting you to consider not proxying Prismic API through your backend as this might lead to some issues, especially with previews, and again here the Javadoc. :relaxed: