{"id":17143772,"url":"https://github.com/harttle/echo.js","last_synced_at":"2025-04-06T03:40:46.369Z","repository":{"id":57219249,"uuid":"90579839","full_name":"harttle/echo.js","owner":"harttle","description":"A server echos raw http request text, for unit test usage","archived":false,"fork":false,"pushed_at":"2018-02-12T14:19:59.000Z","size":21,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-12T15:04:55.462Z","etag":null,"topics":["echo","http-text","server-side-swift"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harttle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-08T02:48:43.000Z","updated_at":"2019-01-15T09:34:46.000Z","dependencies_parsed_at":"2022-08-28T23:22:59.391Z","dependency_job_id":null,"html_url":"https://github.com/harttle/echo.js","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harttle%2Fecho.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harttle%2Fecho.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harttle%2Fecho.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harttle%2Fecho.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harttle","download_url":"https://codeload.github.com/harttle/echo.js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430838,"owners_count":20937873,"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":["echo","http-text","server-side-swift"],"created_at":"2024-10-14T20:42:17.612Z","updated_at":"2025-04-06T03:40:46.353Z","avatar_url":"https://github.com/harttle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# echo.js\n\nEcho raw http request, for test usage.\n\n## Example of using echo.js to test HTTP client\n\nAssuming we have the following HTTP client:\n\n```js\nconst superagent = require('superagent');\n\nfunction getPizzas() {\n    return superagent.get('http://localhost:8061/api/v1/pizzas');\n}\n\nfunction postPizza() {\n    return superagent\n        .post('http://localhost:8061/api/v1/pizzas')\n        .send({ name: 'margherita' })\n        .set('X-API-Key', 'foobar');\n}\n\nmodule.exports = {\n    getPizzas,\n    postPizza,\n};\n```\n\nWe can write something like the following to test how we expect this client's requests to look like:\n\n```js\nconst assert = require('chai').assert;\nconst client = require('./client');\nconst { createServer } = require('echo.js');\n\nconst server = createServer();\nconst port = 8061;\n\nserver.listen(port, function() {\n    /*\n    GET /api/v1/pizzas HTTP/1.1\n    Host: localhost:8061\n    Accept-Encoding: gzip, deflate\n    User-Agent: node-superagent/3.8.2\n    Connection: close\n\n    */\n    const getPizzasPromise = client.getPizzas().then(res =\u003e {\n        // add assertions, e.g.\n        const lines = res.text.split('\\n');\n\n        assert.equal(lines[0], 'GET /api/v1/pizzas HTTP/1.1');\n    });\n\n    /*\n    POST /api/v1/pizzas HTTP/1.1\n    Host: localhost:8061\n    Accept-Encoding: gzip, deflate\n    User-Agent: node-superagent/3.8.2\n    Content-Type: application/json\n    X-API-Key: foobar\n    Content-Length: 21\n    Connection: close\n\n    {\"name\":\"margherita\"}\n    */\n    const postPizzasPromise = client.postPizza().then(res =\u003e {\n        // add assertions, e.g.\n        assert.equal(\n            res.text,\n            [\n                'POST /api/v1/pizzas HTTP/1.1',\n                'Host: localhost:8061',\n                'Accept-Encoding: gzip, deflate',\n                'User-Agent: node-superagent/3.8.2',\n                'Content-Type: application/json',\n                'X-API-Key: foobar',\n                'Content-Length: 21',\n                'Connection: close',\n                '',\n                '{\"name\":\"margherita\"}',\n            ].join('\\n'),\n        );\n    });\n\n    Promise.all([getPizzasPromise, postPizzasPromise])\n        .then(() =\u003e {\n            console.log('All tests pass');\n        })\n        .catch(err =\u003e {\n            console.error(err.message);\n        })\n        .then(() =\u003e {\n            server.close();\n        });\n});\n```\n\nThe same example can be found in this repo's `test` directory.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharttle%2Fecho.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharttle%2Fecho.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharttle%2Fecho.js/lists"}