I have been tinkering on a color viewer for the US Web Design System, nothing too fancy just an easy way to look at the numerous colors in the system with some additional details provided by some external APIs – the colorapi and the WebAIM Color Contrast API. Initially it took me awhile to figure out why I was having a hard time accessing the data and once again I had to remember ho deserializeJSON works. Once I remembered that, it was only a few minutes to create calls to the services.
The colororapi.com service only requires that you pass the type of data you want returned (json) and the hex value for the color you want to look up. Here is the entire code required.
The second service call was to WebAIM Color Contrast API. Like the previous one, the requirements are very simple, pass the background color and the foreground color. One thing that confused me was how to append “&api”. After a couple of tries I decided just to add it to the default cfhttp request and everything started to work fine. Here is the code.
The results can be seen on my other website StphnWlkr.dev.