Skip to content
Tiny API mocking microservice for generating fake JSON data.
TypeScript
Branch: master
Clone or download

Latest commit

Latest commit de32200 Feb 26, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Run tests using CircleCI (fixes #7) Dec 8, 2019
.github Migrate to Meeshkan org Jan 16, 2020
local Minor styling fixes Dec 8, 2019
types Update freddo Jan 16, 2020
.gitignore
.nowignore Add unnecessary files to .nowignore Dec 8, 2019
demo.gif
favicon.png Add favicon Dec 18, 2019
index.ts Migrate to Meeshkan org Jan 16, 2020
now.json Add favicon Dec 18, 2019
package-lock.json Bump codecov from 3.6.1 to 3.6.5 Feb 19, 2020
package.json Bump codecov from 3.6.1 to 3.6.5 Feb 19, 2020
readme.md Fix broken build badge link Feb 26, 2020
test.ts Update freddo Jan 16, 2020
tsconfig.json Update tsconfig Dec 8, 2019

readme.md

micro-jaymock

CircleCI XO Codecov

Tiny API mocking microservice for generating fake JSON data.

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

  • jaymock - API for this module
  • jaymock-cli - Mock an API and generate fake JSON test data, right from the terminal

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

You can’t perform that action at this time.