Shane Bartholomeusz

Geek and lover of all things tech related

Category: Web

How To: Generate Swagger REST API Client

Overview

As the web continues to grow and evolve, API’s are where all the magic happens that powers this innovation. REST API’s have become increasingly more favoured by developers for their ease of use over other alternatives (XML I’m looking at you).

Unfortunately, REST API’s can sometimes become a bit unwieldy in terms of documenting them, and consuming them. It is for this reason that Swagger was born! Swagger will autogenerate documentation for your REST API in the form of an Open API specification (swagger.json) document (formerly Swagger Specification). This makes it much easier for developers to understand and consume an API.

Third-party developers can then use the swagger.json specification file to either manually create an API client or auto-generate one for the preferred language of choice.

In this post, I’ll show you how to autogenerate a C# REST API client from a swagger.json in a few easy steps.

Swagger Logo
Continue reading

Solved: Why Async/Await does not work with .forEach

The Problem

Javascript offers a number of different ways to iterate over an array. Recently while using the array.forEach syntax, I came across some interesting behaviour when using them with the async/await syntax.

To demonstrate. Lets take the following Javascript code which simply prints some messages to the console every 2 seconds.

Javascript Icon
function waitForTwoSecs(i) {
  return new Promise(resolve => {
    setTimeout(() => {
      console.log(`loop iteration ${i}`); 
      resolve('resolved');
    }, 2000);
  });
}

async function mainProgram() {
  const loopIterations = [1, 2, 3];
  console.log('mainProgram Start');

  loopIterations.forEach(async iteration =>  {
    const result = await waitForTwoSecs(iteration);
  });

  console.log('mainProgram finished'); 
}

mainProgram();
Continue reading

How To: Deep Clone a JavaScript Object

Overview

JavaScript is becoming ever increasingly more popular as time goes by. While JavaScript has many advantages, it also has many interesting quirks or nuances that can catch out new beginners.

In this post I’ll show you how to deep clone a JavaScript object.

Problem

Okay … before we go any further … lets take a step back and understand the problem at hand.

Objects in JavaScript are passed by reference, meaning that any object returned by a function will point to the same memory reference as the original object. Therefore if the caller of the function modifies the returned object, they will actually be changing the original source object.

Javascript Icon
Continue reading

How To: Google Analytics In Chrome Extensions

Background

Google Analytics

Google has replaced its legacy analytics library https://ssl.google-analytics.com/ga.js with the new and improved Universal Analytics library https://www.google-analytics.com/analytics.js.

I’ve been working on a Google Chrome Browser Extension but had some trouble integrating it with Google Analytics. Google’s own tutorial hadn’t yet been updated to use the new analytics library. In this post I’ll explain how I did it.

Continue reading

Reduce Google Chrome Memory Usage

Google Chrome
As a web developer I regularly use Google Chrome for it’s great debugging features. As much as I love Google Chrome it can be a bit of a pig sometimes … it lovessss eating memory!

Continue reading

Top 7 VS Code Extensions

VS Code Logo

I love Visual Studio Code! It’s a fantastic lightweight, cross-platform source code editor from Microsoft. Best of all, it’s FREE!!!

Starting with Visual Studio Code Beta (0.10.1 version) you can install extensions from the Visual Studio Code Marketplace to further enhance its functionality.

Here’s is my list of must-have extensions for VS Code:

Continue reading

Progressive Web Apps: Future of the Web?

Decisions, Decisions, Decisions …

Progressive Web App ExampleIn today’s rapidly evolving world of technology there has always been a clear distinction between mobile apps and websites. They each bring along their own set of pros and cons.

Although native mobile apps provide a first class user experience, they tend to have a higher barrier to entry; they require installation and are typically more difficult to develop/maintain. Websites on the other hand are platform agnostic and are typically easier to develop and maintain, however they provide a less engaging user experience.

In this article I’ll touch on a new technology called Progressive Web Apps which aims to bring these disparate worlds together. It may very well be the future of the web!

Continue reading

© 2024 Shane Bartholomeusz

Theme by Anders NorenUp ↑