Home

Awesome

micro-jaymock

CircleCI XO Codecov

Tiny API mocking microservice for generating fake JSON data.

<img src="demo.gif" width="800">

Usage

Examples

Using curl:

~ ❯❯❯ curl -X POST \
        -d '{ "firstName": "name.firstName", "lastName": "name.lastName" }' \
        https://jaymock.now.sh
{"firstName":"Isaac","lastName":"Schultz"}

Using httpie:

~ ❯❯❯ http -b POST https://jaymock.now.sh \
        firstName=name.firstName lastName=name.lastName ssn=chance.ssn \
        _repeat:=3
[
    {
        "firstName": "Jalyn",
        "lastName": "Weimann",
        "ssn": "493-64-4894"
    },
    {
        "firstName": "Alvah",
        "lastName": "Ziemann",
        "ssn": "567-92-8024"
    },
    {
        "firstName": "Bennett",
        "lastName": "Russel",
        "ssn": "356-24-9256"
    }
]

Using request (Node.js):

const request = require('request')
const template = {
	firstName: 'name.firstName',
	lastName: 'name.lastName',
	ipAddresses: 'internet.ip|2'
}
request.post({url: 'https://jaymock.now.sh', json: template}, (error, response, body) => {
    if (error) {
        /* Handle error */
        console.error(error)
    }
    console.log(body)
    /*
        {
            firstName: 'Kaley',
            lastName: 'Muller',
            ipAddresses: [ '118.171.253.32', '193.234.186.225' ]
        }
    */
})

Using got (Node.js):

const got = require('got');
const template = {
    name: 'fake({{name.lastName}}, {{name.firstName}} {{name.suffix}})',
    ssn: 'chance.ssn',
    knownAddresses: {
        street: 'address.streetAddress',
        city: 'address.city',
        zipCode: 'address.zipCode',
        _repeat: 2
    }
};
(async () => {
    const {body} = await got.post('https://jaymock.now.sh', {
        json: template,
        responseType: 'json'
    });
    console.log(body);
    /*
        {
            name: 'Goodwin, Libby II',
            ssn: '368-52-3834',
            knownAddresses: [
                {
                    street: '42483 Citlalli Viaduct',
                    city: 'West Joeybury',
                    zipCode: '43966-8850'
                },
                {
                    street: '36297 Estella Throughway',
                    city: 'South Claudie',
                    zipCode: '39189-1653'
                }
            ]
        }
    */
})();

Using requests (Python 3):

import requests, json
template = {
	"accounts": {
		"name": "finance.accountName",
		"iban": "finance.iban",
		"bic": "finance.bic",
		"currentBalance": "finance.amount",
		"currency": "finance.currencyName",
		"_repeat": 2
	}
}
r = requests.post('https://jaymock.now.sh', data = json.dumps(template))
parsedFakeData = json.loads(r.text) # parse for pretty-printing
print(json.dumps(parsedFakeData, indent=4, sort_keys=True))
"""
	{
		"accounts": [
			{
				"bic": "WNRUMKJ1",
				"currency": "Turkish Lira",
				"currentBalance": "37.49",
				"iban": "CY70805008804937709053145O66",
				"name": "Credit Card Account"
			},
			{
				"bic": "LTJUMXQ1",
				"currency": "Somoni",
				"currentBalance": "98.10",
				"iban": "FI1000486540190178",
				"name": "Home Loan Account"
			}
		]
	}
"""

Development

First, clone the repository and install its dependencies:

~ ❯❯❯ git clone https://github.com/Meeshkan/micro-jaymock.git
~ ❯❯❯ cd micro-jaymock/
~/micro-jaymock ❯❯❯ npm install

Subsequently, start the development server:

~/micro-jaymock ❯❯❯ npm run dev

You can then access the service by navigating to localhost:3000.

Alternatively, you can download jaymock-cli (by running ~ ❯❯❯ npm i -g jaymock-cli), which allows you to run the development server and, consequently, mock a fake API 'globally' (by simply executing ~ ❯❯❯ jaymock --server).

Deployment

Deploy to now

Alternatively, to deploy micro-jaymock manually:

First, download now:

~ ❯❯❯ npm install -g now

Then, run now from within the micro-jaymock directory:

~/micro-jaymock ❯❯❯ now

Related

Contributing

Thanks for wanting to contribute! We will soon have a contributing page detailing how to contribute. Meanwhile, feel free to star this repository, open issues, and ask for more features and support.

Please note that this project is governed by the Meeshkan Community Code of Conduct. By participating in this project, you agree to abide by its terms.

Credits

License

MIT © Meeshkan