Testing the SDL Web 8 micro-services

microservicesA couple of days ago, at the Tridion Developer summit, I did a “lightning talk” where in fifteen minutes flat, I rattled through my recent experiences of setting up publishing and content delivery using the new Topology Manager and micro-services in SDL Web 8. It’s hard to go into much detail in fifteen minutes, so on one level it’s just a bit of fun, but I hope I also managed to help people avoid some of the pain points.

Whenever I’m setting up infrastructure, one thing I’m very keen on is being able to test the individual pieces independently. That way you can move on to the next piece confident that when you run it all together, there is a good chance of it working. So in my talk, one of the things I demonstrated was a simple PowerShell script that checks if the content service is working. After my talk, several people approached me to discuss points that I’d raised, and by far the most popular item, it seems, was this script. So here it is:

The reason why people found it interesting is that these services are a bit tricky to test with a browser, because you need to send an OAuth authorisation header. There are browser plugins that can help with this, but personally, I like the idea of having a script like this in my tool box. Of course, it’s pretty rough and ready, but it serves to show how you can do a very simple test:

  1. Put the required authentication details into a hash, and put this in the body of a POST request to the token service. (Here I’ve used the ‘cduser’ account with the default credentials, but of course, in production systems, you’ll need to match the credentials configured in the cd_ambient_conf.xml file of the discovery service.)
  2. Extract the authorisation token from the response and use it to create the Authorization header of your call to the content service.
  3. What you do with the output data is really up to you. I’ve queried for ‘/Publications’, and then used an xpath to fish the relevant text out of the response. You can easily modify this to do different queries and process the output differently.

The main point here is that you can verify that things are working correctly with just a few lines of code. I expect that over time I will make a more generic or fully featured version that does somewhat more. Obviously, you can use the same technique to test the other services, and it should also be possible (as suggested to me by Renze de Vries) to first query the discovery service, obtain the endpoints for the various capabilities, and then test them all in turn.

I hope you’ll find this technique helpful, and of course, I’d love to hear of any improvements you come up with, or interesting variations.

  • Chris Mills

    I wish I had found your PowerShell earlier, I did something very similar using “New-Object System.Net.WebClient” but
    “Invoke-RestMethod” is so much better. Thanks for posting your solution.

  • Nice post, Dominic. I’ve bookmarked this, as I know I’m going to be needing it some time soon!