Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

✨ Scenario-based HTTP mocking

License

NotificationsYou must be signed in to change notification settings

americanexpress/parrot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parrot

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.

👩‍💻 Hiring 👨‍💻

Want to get paid for your contributions toparrot?

Send your resume tooneamex.careers@aexp.com

🤹‍ Usage

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.

Add them to your server

importexpressfrom'express';importparrotfrom'parrot-middleware';importscenariosfrom'./scenarios';constapp=express();app.use(parrot(scenarios));app.listen(3000);

Develop with Parrot'sdevtools

parrot-devtools

Example API requests

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'

📦 Packages

Parrot is divided into several packages that can be used together depending on your use case.

NameDescription
parrot-coreCore Parrot functionality that can be extended to new use cases
parrot-devtoolsDevtools that allow you to switch between Parrot scenarios
parrot-fetchFetch mocking implementation of Parrot
parrot-friendlyHelper library to write your scenarios in BDD style
parrot-graphqlHelper library to add GraphQL mocks to your scenarios
parrot-middlewareExpress middleware implementation of Parrot
parrot-serverCLI to get a parrot server up and running

🏆 Contributing

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.

🗝️ License

Any contributions made under this project will be governed by theApache License 2.0.

🗣️ Code of Conduct

This project adheres to theAmerican Express Community Guidelines.By participating, you are expected to honor these guidelines.


[8]ページ先頭

©2009-2025 Movatter.jp