meeshkan / Micro Jaymock
Programming Languages
Projects that are alternatives of or similar to Micro Jaymock
micro-jaymock
Tiny API mocking microservice for generating fake JSON data.
Usage
- Send a
POST
request tohttps://jaymock.now.sh/
(orhttps://micro-jaymock.now.sh/
) with your JSON template (seejaymock.populate
'stemplate
parameter) as your request'sbody
.
Examples
curl
:
Using ~ ❯❯❯ curl -X POST \
-d '{ "firstName": "name.firstName", "lastName": "name.lastName" }' \
https://jaymock.now.sh
{"firstName":"Isaac","lastName":"Schultz"}
httpie
:
Using ~ ❯❯❯ 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"
}
]
request
(Node.js):
Using 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' ]
}
*/
})
got
(Node.js):
Using 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'
}
]
}
*/
})();
requests
(Python 3):
Using 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
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
-
Faker.js
is used asjaymock
's core fake data generator. -
chance
is imported as a fake data generator dependency (usingjaymock.extend
). -
micro
is used to serve this HTTP microservice.
License
MIT © Meeshkan