DEV Community

Shubhendu Madhukar
Shubhendu Madhukar

Posted on

File Based API Mocking in JavaScript

It's been a while, since I wrote about Camouflage. There have been some exciting developments in past few months and I would like to present the new features Camouflage has to offer to support your prototyping/testing needs.

What is Camouflage?

For the uninitiated, Camouflage is a mocking tool, used to stub the backends based on various protocols, such as http, https, http2, grpc and websockets.

Camouflage helps you carry out your front end prototyping, unit testing, functional/performance testing in silos, in absence of one or more Microservices/APIs. If you'd like to read more, visit my previous post

What's new in Camouflage?

Some of the things I have been working on for past few months are:

  • A fully customizable caching mechanism. Compared to earlier versions where cache was stored only in memory, you can now use redis for caching.
  • Connection to external data sources. Most mocking tools rely on random data such as names, uuids, random numbers etc to make your response dynamic. But sometimes, that's not enough. Even though you are just building a mock, you might at times, need to connect to a real data source instead of just random data. Camouflage supported CSV files as data source in previous versions, but now you can also use postgres as your data source. (MySQL/Mongo to be supported soon)
  • Containerization. Camouflage can now be deployed on docker environments, and kubernetes. Simply use the enclosed docker-compose.yml and kubernetes/*.yaml to quickly spin up a Camouflage environment

Full list of features

🔥 File based mocking support for HTTP, HTTPS, HTTP2, gRPC and websockets. 🔥

⚡ Dynamic/realistic responses without having to write any code. ⚡

🧩 Flexibility to partially or fully code your responses. 🧩

🎯 Conditional responses based on request parameters. 🎯

🌟 Inbuilt Caching - In memory and redis. 🌟

🧮 Ability to fetch and condition the response using external data. Currently supported data sources are CSV and postgres. 🧮

⏳ Delay Simulation. ⏳

🔍 Inbuilt monitoring. 🔍

🦺 Inbuilt backup and restore mechanism. 🦺

⏩ Quick start with camouflage init and camouflage restore modules. ⏩

🎊 Deployable on standalone VMs, Dockers and Kubernetes. 🎊

📁 Comes with a file explorer UI that allows modification of mock files hosted remotely. 📁

What is in works?

Camouflage is now reaching a stable state, which means a large part of effort would be focused on maintenance, resolving dependency vulnerability, cleaning up and commenting code, building an up-to-date JSDocs, supporting newer releases of Node (Camouflage can be run on systems with Node <v15).

New functionalities on the road map are introducing few more data source compatibility, breaking down Camouflage from one large package to smaller modules that can be used as plugins, and eventually migrating from express to fastify.

Check out the project @ Github. Leave a 🌟 if you'd like what you see, drop suggestions or ask questions, we'd love every bit of support we can get. To know all the details about Camouflage, refer to documentation

Top comments (0)