{"id":22278477,"url":"https://github.com/devjack/echo-api-example","last_synced_at":"2025-03-25T18:22:06.761Z","repository":{"id":50209730,"uuid":"124642047","full_name":"devjack/echo-api-example","owner":"devjack","description":"A simple echo API to demonstrate that API spec's are for more than just documentation.","archived":false,"fork":false,"pushed_at":"2021-06-01T22:02:21.000Z","size":97,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-30T15:49:33.124Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devjack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-10T09:42:39.000Z","updated_at":"2018-04-02T09:52:19.000Z","dependencies_parsed_at":"2022-09-24T08:01:27.369Z","dependency_job_id":null,"html_url":"https://github.com/devjack/echo-api-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjack%2Fecho-api-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjack%2Fecho-api-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjack%2Fecho-api-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devjack%2Fecho-api-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devjack","download_url":"https://codeload.github.com/devjack/echo-api-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245516985,"owners_count":20628258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T15:14:39.836Z","updated_at":"2025-03-25T18:22:06.738Z","avatar_url":"https://github.com/devjack.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Echo API Example\nThis is a simple API to echo back a string. It's primary purpose is to demonstrate that API spec's are for more than just documentation.\n\nIn this example, an OpenAPI spec is used for\n\n* Mocking an API as a prototype\n* Testing an API implementation against the spec\n* Generating Postman collections for deeper testing\n* Eventually, generating documentation\n\n## Mocking a new API\nFirst, for the purposes of rapid prototyping, craft an API spec using tools like SwaggerHub.\n\nHere's a [spec I created earlier](https://app.swaggerhub.com/apis/devjack/Echo-API-Example/1.0.0) that allows you to do some mock API calls.\n\n\n## Implementing that API\nStart coding against the API spec to implement various features. This API is quite simple, just an `/echo` endpoint.\n\n### Code Generation\nYou _can_ use a variety of tools to generate code from your API spec.\n\n```\npip install swagger_py_codegen\nswagger_py_codegen -s openapi.yml . -p echo\n```\n\nTo make this work for the spec I've then gone and modified the `/v1` prefix in the blueprint, and the `echo/v1/api/echo.py` file to implement `?echo`.\n\nI personally, however, am not a fan of code-gen and code magic in general. So, for such a simple API I prefer to setup and implement this myself.\n\n### Implementation\nIf implementing this yourself then you want to setup the repo (or just clone this one) and then go ahead and install the dependencies.\n\n#### Setup\n```\ngit clone https://github.com/devjack/echo-api-example.git \u0026\u0026 cd echo-api-example\n\n# A simple virtual env for this project\npython -m venv ../echo-api-example.env\n. ../echo-api-example.env/bin/activate\n```\n\n#### Dependencies\nSimplest - use requirements.txt\n\n```\npip install -r requirements.txt\n```\n\nIf you prefer, you can install the three dependencies directly.\n\n```\npip install zappa flask\n```\n\n## Test against the spec\nWe'll use dredd to do this.\n\n```\nnpm install -g dredd\ndredd init\ndredd\n```\n\n\n## Extra tests (Postman)\nYou can [import an OpenAPI spec to postman](https://www.getpostman.com/docs/v6/postman/collections/data_formats). But, I've already done that for you in `echo-example.postman_collection.json`.\nYou can then [write tests against API calls](https://www.getpostman.com/docs/v6/postman/scripts/test_scripts). For more reading I'd highly recommend reading this [excellent collection of tips](http://blog.getpostman.com/2017/07/28/api-testing-tips-from-a-postman-professional/) for API testing.\n\nSince we already have a postman collection in the repo:\n\n```\nnpm install -g newman\nnewman run echo-example.postman_collection.json\n```\n\n## Deployment\nFrom scratch, you can run `zappa init` to setup a serverless deployment.\n\nI've already generated (and further configured for TLS and a custom domain etc) so deployments are run by:\n\n```\n# First time\nzappa deploy\n\n# subsequent times\nzappa update production\n```\n\nSee `zappa_settings.json` for an example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevjack%2Fecho-api-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevjack%2Fecho-api-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevjack%2Fecho-api-example/lists"}