- Notifications
You must be signed in to change notification settings - Fork30
✨ Scenario-based HTTP mocking
License
americanexpress/parrot
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Parrot is a set of tools that allow you to create HTTP mocks and organize them into scenarios in order to develop your app against different sets of data. We have implemented all of Parrot's functionality in JavaScript, butscenarios are a general specification that can be implemented in any language.
Want to get paid for your contributions toparrot
?
Send your resume tooneamex.careers@aexp.com
Let's walk through a common development workflow using Parrot.
Define yourscenarios
import{describe,it,get,post,graphql}from'parrot-friendly';importcasualfrom'casual';// for generating fake dataimportschemafrom'./schema';// our GraphQL schemaconstscenarios=describe('Ship Log',()=>{it('has a ship log',()=>{// respond with a mock JSON file and add a delayget('/ship_log').response(require('./mocks/shipLog.json')).delay(1200);// respond with the request body that was sentpost('/ship_log').response(req=>req.body);});it('has a random ship log',()=>{// respond with random data generated by casualget('/ship_log').response(()=>[{port:casual.city,captain:casual.full_name,},]);});it('has a server error',()=>{// respond with a 500 statusget('/ship_log').status(500);});it('has a ship log from GraphQL',()=>{// respond to GraphQL queriesgraphql('/graphql',schema,()=>({ShipLog:()=>require('./mocks/shipLog.json'),}));});});exportdefaultscenarios;
More information about writing scenarios can be found in thescenarios documentation.
importexpressfrom'express';importparrotfrom'parrot-middleware';importscenariosfrom'./scenarios';constapp=express();app.use(parrot(scenarios));app.listen(3000);
Develop with Parrot'sdevtools
Fetch current scenario.
$ curl'http://localhost:3002/parrot/scenario'
Fetch all scenarios.
$ curl'http://localhost:3002/parrot/scenarios'
Setting parrot to a new scenario.
$ curl -X POST -H"Content-Type: application/json" -d'{ "scenario": "[scenario name here]" }''http://localhost:3002/parrot/scenario'
Parrot is divided into several packages that can be used together depending on your use case.
Name | Description |
---|---|
parrot-core | Core Parrot functionality that can be extended to new use cases |
parrot-devtools | Devtools that allow you to switch between Parrot scenarios |
parrot-fetch | Fetch mocking implementation of Parrot |
parrot-friendly | Helper library to write your scenarios in BDD style |
parrot-graphql | Helper library to add GraphQL mocks to your scenarios |
parrot-middleware | Express middleware implementation of Parrot |
parrot-server | CLI to get a parrot server up and running |
We welcome Your interest in the American Express Open Source Community on Github.Any Contributor to any Open Source Project managed by the American Express OpenSource Community must accept and sign an Agreement indicating agreement to theterms below. Except for the rights granted in this Agreement to American Expressand to recipients of software distributed by American Express, You reserve allright, title, and interest, if any, in and to Your Contributions. Pleasefill out the Agreement.
Please see ourCONTRIBUTING.md.
Any contributions made under this project will be governed by theApache License 2.0.
This project adheres to theAmerican Express Community Guidelines.By participating, you are expected to honor these guidelines.
About
✨ Scenario-based HTTP mocking