Octopus API Part 3: Making Generic Helper Functions

Hello!

So last time we created a function to return an Octopus release by passing the project id property that we retrieved from a function that we had created before. This “Get-Property” function was nice and generic: we could give it any valid uri and it would return any given property, providing it exists. But the get release function served one purpose: to return just the releases for one project. Looking through the Octopus API there’s quite a few resources, and many of them follow the same pattern: just look at the documentation for Channels and Releases. Without too much effort we could make a couple of generic functions that would serve a large amount of the calls we need to make.

But before we get ahead of ourselves, let’s get right back to the fundamentals. We’re going to use a URI to execute an operation against the API. So let’s create a generic “Get-Uri” function that will build up the URI for us. And because  double forward slashes like “//”, or multiple entires of “/api/” can exist, let’s create a function that we can use to strip characters off the the root uris, the links available in API objects, and segments built up in the scripts.

These are generic help functions, almost meta functions we can use in the other functions (sup dog, I heard you like functions, or something.) Next post we’ll push on from this and create some functions that can form the basis of using a large part of the Octopus API.

Leave a Reply

Your email address will not be published. Required fields are marked *