GithubHelp home page GithubHelp logo

testinggospels / camouflage_deno Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.65 MB

HTTP/HTTPs Mocking tool

Home Page: https://testinggospels.github.io/camouflage_deno/

License: MIT License

TypeScript 11.96% HTML 75.80% JavaScript 12.24%
testing rest stub mocking service-virtualization camouflage

camouflage_deno's Introduction

Getting Started

camouflage.png

Full Documentation

Camouflage is a service virtualization tool inspired by namshi/mockserver. As the original description says, the mocking/service virtualization works on a file based structure where you simply organize your mocked HTTP responses in a bunch of mock files and it will serve them like they were coming from a real API; in this way you can write your frontends without caring too much whether your backend is really ready or not.

  • Camouflage is a deno module, therefore to install Camouflage, you'd need to install Deno first, if you haven't already done so.
  • You can then import Camouflage into your project:
import { CamouflageConfig, CamouflageServer } from "https://deno.land/x/[email protected]/mod.ts";
  • Note that you'd also need to provide a config file to initialize Camouflage.
import { YamlLoader } from "https://deno.land/x/yaml_loader/mod.ts";
const configLoader = new YamlLoader();
const config: CamouflageConfig = <CamouflageConfig>await configLoader.parseFile("./config.yaml");
  • Create a config.yaml file at the root of your project. And paste the following content (update if required).
loglevel: INFO
protocols:
  http:
    enable: true
    port: 8080
    mocks: "./mocks"
  https:
    enable: true
    port: 8443
    cert: "./certs/server.crt"
    key: "./certs/server.key"
  • In case you need HTTPs endpoints, create .crt and .key files before starting the server. For testing purposes you can generate a self-signed certificate. If HTTPs endpoints are not required, update above config.yaml to disable https protocol
openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 365 -keyout server.key -out server.crt
  • For simplicity, create an inputs array to store the configs in following order.
const inputs = [
  config.loglevel,
  config.protocols.http.enable,
  config.protocols.http.port,
  config.protocols.http.mocks,
  config.protocols.https.enable,
  config.protocols.https.port,
  config.protocols.https.cert,
  config.protocols.https.key,
];
  • Finally, create an instance of CamouflageServer and call start() by spreading the inputs array as it's parameters
const camouflageServer: CamouflageServer = new CamouflageServer();
// @ts-ignore ignore
camouflageServer.start(...inputs);
  • Run using the command
deno run --allow-net --allow-read --allow-write --unstable test.ts

Create your first mock

Camouflage follows the same convention as mockserver to create mocks. For example,

All further references to the variable ${MOCK_DIR} in this documentation will refer
to the directory you have specified in your config.yaml file under
config.protocols.http.mocks
  1. You start by creating a directory ${MOCKS_DIR}/hello-world
  2. Create a file GET.mock under ${MOCKS_DIR}/hello-world.
  3. Paste following content:
HTTP/1.1 200 OK
X-Custom-Header: Custom-Value
Content-Type: application/json

{
    "greeting": "Hey! It works!"
}

Navigate to http://localhost:8080/hello-world

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.