Package: meeshkan
MeeshkanMeeshkan is a tool that mocks HTTP APIs for use in sandboxes as well as for automated and exploratory testing. It uses a combination of API definitions, recorded traffic and code in order to make crafting mocks as enjoyable as possible.Chat with us on Gitterto let us know about questions, problems or ideas!What's in this documentInstallationGetting started with MeeshkanTutorialCollect recordings of API trafficBuild a Meeshkan spec from recordingsBuilding modesMock server traffic using a Meeshkan specDevelopmentGetting startedTestsType-checkingAutomated buildsPublishing Meeshkan as a PyPi packageContributingCode of ConductInstallationInstall viapip(requiresPython 3.6+):pipinstallmeeshkanmacOS users can install Meeshkan withHomebrew:brewtapmeeshkan/tap
brewinstallmeeshkanDebian and Ubuntu users can install Meeshkan withapt:echo"deb [trusted=yes] https://dl.bintray.com/meeshkan/apt all main"|tee-a/etc/apt/sources.list
apt-get-qqupdate&&apt-getinstallmeeshkanGetting started with MeeshkanThe basic Meeshkan flow iscollect, build and mock.First,collectdata from recorded server traffic and/or OpenAPI specs.Then,builda schema that unifies these various data sources.Finally, use this schema to create amockserver of an API.TutorialThe quickest way to get an overview of Meeshkan is to complete ourinteractive tutorial. It walks you through the collect, build, and mock flow - while also covering the concepts necessary for development.First, installmeeshkan-tutorialviapip:$pipinstallmeeshkan-tutorial
$meeshkan-tutorialNote: This tutorial has been tested on Python 3.6, 3.7, and 3.8.After installing, you can begin the tutorial by invoking from the command line:$meeshkan-tutorialOnce you've run this, you should see:______________________//_//___________/__`__\/_\/_\/___/__\///_/__`/__\//////__/__(__)///,<//_/////
/_//_//_/\___/\___/____/_//_/_/|_|\__,_/_//_/


Thetutorial!!
PressENTERtocontinue...If not, it's probably our fault. Please let us know byfiling an issue on the meeshkan-tutorial repo.Collect recordings of API trafficLet's look at how to build a Meeshkan spec. First, you have tocollectrecordings of server traffic and/or OpenAPI server specs.To record API traffic, the Meeshkan CLI provides arecordmode that captures API traffic using a proxy.$meeshkanrecordThis command starts Meeshkan as a reverse proxy on the default port of8000and creates two directories:logsandspecs.Withcurl, for example, you can use Meeshkan as a proxy like so:$curlhttp://localhost:8000/http://api.example.comBy default, the recording proxy treats the path as the target URL. It then writes a.jsonlfile containing logs of all server traffic to thelogsdirectory.  All logs are created in thehttp-typesformat. This is because Meeshkan'sbuildtool expects all recordings to be represented in a.jsonlfile containing recordings represented in thehttp-typesformat.For more information about recording, including direct file writing and kafka streaming, see therecording documentation.Build a Meeshkan spec from recordingsUsing the Meeshkan CLI, you canbuildan OpenAPI schema from a single.jsonlfile, in addition to any existing OpenAPI specs that describe how your service works.$meeshkanbuild--input-filepath/to/recordings.jsonlNote: The input file should be inJSON Linesformat and every line should be inhttp-typesJSON format. For an example input file, seerecordings.jsonl.Optionally, you can also specify an output directory using the--outflag followed by the path to this directory. By default, Meeshkan will build the new OpenAPI specifications in thespecsdirectory.Use dash (--input-file -) to read from standard input:$meeshkanbuild--input-file-<recordings.jsonlBuilding modesYou can use a mode flag to indicate how the OpenAPI spec should be built, for example:meeshkanbuild--input-filepath/to/recordings.jsonl--modegenSupported modes are:gen [default] - infer a schema from the recorded datareplay - replay the recorded data based on exact matchingFor more information about building, including mixing together the two modes and editing the created OpenAPI schema, see thebuilding documentation.Mock server traffic using a Meeshkan specYou can use an OpenAPI spec, such as the one created withmeeshkan build, to create amockserver using Meeshkan.$meeshkanmockpath/to/dir/Note: You can specify a path to the directory your OpenAPI spec is in or a path to one specific file.For more information about mocking, including adding custom middleware and modifying the mocking schema JIT via an admin API, see themocking documentation.DevelopmentHere are some useful tips for building and running Meeshkan from source.If you run into any issues, pleasereach out to our team on Gitter.Getting startedClone this repository:git clone https://github.com/meeshkan/meeshkanCreate a virtual environment:virtualenv .venv && source .venv/bin/activateInstall dependencies:pip install --upgrade -e '.[dev]'TestsRun all checks:$pythonsetup.pytestpytestRuntests/withpytest:pytest# orpythonsetup.pytestConfiguration forpytestis found inpytest.ini.FormattingFormatting is checked by the above mentionedpython setup.py testcommand.To fix formatting:$pythonsetup.pyformatflake8Run style checks:$flake8.pyrightYou can run type-checking by installingpyrightglobally:$npm-i-gpyrightAnd then running:$pyright--lib
$# or$pythonsetup.pytypecheckUsing thePyright extensionis recommended for development in VS Code.Automated buildsConfiguration for CircleCIbuild pipelinecan be found in.circleci/config.yml.Publishing Meeshkan as a PyPi packageTo publish Meeshkan as a PyPi package, complete the following steps:Bump the version insetup.pyif the version is the same as in the publishedpackage. Commit and push.Runpython setup.py testto check that everything worksTo build and upload the package, runpython setup.py upload. Insert PyPI credentials to upload the package toPyPI. The command will also rungit tagto tag the commit as a release and push the tags to remote.To see what the different commands do, seeCommandclasses insetup.py.ContributingThanks for your interest in contributing! Please take a look at ourdevelopment guidefor notes on how to develop the package locally.  A great way to start contributing is tofile an issueormake a pull request.Code of ConductPlease note that this project is governed by theMeeshkan Community Code of Conduct. By participating, you agree to abide by its terms.