From ca58bbd18d7ecf901e9079951cf81778df6395b9 Mon Sep 17 00:00:00 2001 From: Engin Yoeyen Date: Thu, 8 Apr 2021 13:03:42 +0200 Subject: [PATCH] Add more examples --- examples/README.md | 54 ++++++++++++++++ .../{ => fault-simulation}/with-delay.json | 2 +- .../get-authenticated-user-fails.json | 16 +++++ .../get-authenticated-user.json | 61 +++++++++++++++++++ .../github-user-api/get-user-hovercard.json | 20 ++++++ examples/github-user-api/get-user.json | 58 ++++++++++++++++++ examples/github-user-api/get-users.json | 36 +++++++++++ examples/github-user-api/patch-user.json | 61 +++++++++++++++++++ examples/http-get-json-payload.json | 33 ---------- examples/http-post.json | 1 - examples/response-with-json-payload.json | 18 ++++++ examples/simple-http-get.json | 6 +- 12 files changed, 326 insertions(+), 40 deletions(-) create mode 100644 examples/README.md rename examples/{ => fault-simulation}/with-delay.json (89%) create mode 100644 examples/github-user-api/get-authenticated-user-fails.json create mode 100644 examples/github-user-api/get-authenticated-user.json create mode 100644 examples/github-user-api/get-user-hovercard.json create mode 100644 examples/github-user-api/get-user.json create mode 100644 examples/github-user-api/get-users.json create mode 100644 examples/github-user-api/patch-user.json delete mode 100644 examples/http-get-json-payload.json create mode 100644 examples/response-with-json-payload.json diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..f6ec007 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,54 @@ +# Mapping Examples +This directory contains different examples of HTTP request/response. + +Once you start the `mimic` with these examples(simply downmload and point `mimic` to directory), content of each JSON file will turn be used to create appropiate HTTP endpoint. + +### GitHub User API Examples +Some examples from GitHub user API which can be tested via following commands + +```` +# Will return 200 with a user response in get-authenticated-user.json file +curl -i http://localhost:8080/user -H "Authorization: token someValidToken" + + +# Will return 401 with a response in get-authenticated-user-fails.json file +curl -i http://localhost:8080/user -H "Authorization: token someInvalidToken" + + +# Will return 200 with a response in get-user.json file +curl -i http://localhost:8080/user/octocat + +# username is dynamic, which means following example will return the same response +curl -i http://localhost:8080/user/someotheruser + +```` + +For more details check out the JSON files. + + +### Fault Simulation +Purpose of fault simulation is to create artificial failures in responses. At this stage only supported failure is response-delay. + +```` +{ + "request":{ + "url": "/health", + "method" : "GET" + + }, + "response":{ + "status": 200, + "body": "All healthy", + "headers":{ + "Content-Type":"text/plain" + }, + "withDelay": 4000 + } +} + +```` +The mapping above, will delay the response for 4 seconds, try it out with: + +```` +curl -i http://localhost:8080/health +```` \ No newline at end of file diff --git a/examples/with-delay.json b/examples/fault-simulation/with-delay.json similarity index 89% rename from examples/with-delay.json rename to examples/fault-simulation/with-delay.json index 98d5e4b..8cd132d 100644 --- a/examples/with-delay.json +++ b/examples/fault-simulation/with-delay.json @@ -10,6 +10,6 @@ "headers":{ "Content-Type":"text/plain" }, - "withDelay": 2000 + "withDelay": 4000 } } \ No newline at end of file diff --git a/examples/github-user-api/get-authenticated-user-fails.json b/examples/github-user-api/get-authenticated-user-fails.json new file mode 100644 index 0000000..9e40e5e --- /dev/null +++ b/examples/github-user-api/get-authenticated-user-fails.json @@ -0,0 +1,16 @@ +{ + "request":{ + "url": "/user", + "method" : "GET", + "headers":{ + "Authorization": "token someInvalidToken" + } + }, + "response":{ + "status": 401, + "body": { + "message": "Requires authentication", + "documentation_url": "https://docs.github.com/rest/reference/users#get-the-authenticated-user" + } + } +} \ No newline at end of file diff --git a/examples/github-user-api/get-authenticated-user.json b/examples/github-user-api/get-authenticated-user.json new file mode 100644 index 0000000..f4affc9 --- /dev/null +++ b/examples/github-user-api/get-authenticated-user.json @@ -0,0 +1,61 @@ +{ + "request":{ + "url": "/user", + "method" : "GET", + "headers":{ + "Authorization": "token someValidToken" + } + }, + "response":{ + "status": 200, + "body": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false, + "name": "monalisa octocat", + "company": "GitHub", + "blog": "https://github.com/blog", + "location": "San Francisco", + "email": "octocat@github.com", + "hireable": false, + "bio": "There once was...", + "twitter_username": "monatheoctocat", + "public_repos": 2, + "public_gists": 1, + "followers": 20, + "following": 0, + "created_at": "2008-01-14T04:33:35Z", + "updated_at": "2008-01-14T04:33:35Z", + "private_gists": 81, + "total_private_repos": 100, + "owned_private_repos": 100, + "disk_usage": 10000, + "collaborators": 8, + "two_factor_authentication": true, + "plan": { + "name": "Medium", + "space": 400, + "private_repos": 20, + "collaborators": 0 + } + }, + "headers":{ + "Content-Type":"application/json" + } + } +} \ No newline at end of file diff --git a/examples/github-user-api/get-user-hovercard.json b/examples/github-user-api/get-user-hovercard.json new file mode 100644 index 0000000..49b392c --- /dev/null +++ b/examples/github-user-api/get-user-hovercard.json @@ -0,0 +1,20 @@ +{ + "request":{ + "url": "/users/{username}/hovercard", + "method" : "GET" + }, + "response":{ + "status": 200, + "body": { + "contexts": [ + { + "message": "Owns this repository", + "octicon": "repo" + } + ] + }, + "headers":{ + "Content-Type":"application/json" + } + } +} \ No newline at end of file diff --git a/examples/github-user-api/get-user.json b/examples/github-user-api/get-user.json new file mode 100644 index 0000000..ec57f2b --- /dev/null +++ b/examples/github-user-api/get-user.json @@ -0,0 +1,58 @@ +{ + "request":{ + "url": "/user/{username}", + "method" : "GET" + }, + "response":{ + "status": 200, + "body": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false, + "name": "monalisa octocat", + "company": "GitHub", + "blog": "https://github.com/blog", + "location": "San Francisco", + "email": "octocat@github.com", + "hireable": false, + "bio": "There once was...", + "twitter_username": "monatheoctocat", + "public_repos": 2, + "public_gists": 1, + "followers": 20, + "following": 0, + "created_at": "2008-01-14T04:33:35Z", + "updated_at": "2008-01-14T04:33:35Z", + "private_gists": 81, + "total_private_repos": 100, + "owned_private_repos": 100, + "disk_usage": 10000, + "collaborators": 8, + "two_factor_authentication": true, + "plan": { + "name": "Medium", + "space": 400, + "private_repos": 20, + "collaborators": 0 + } + }, + "headers":{ + "Content-Type":"application/json" + } + } +} \ No newline at end of file diff --git a/examples/github-user-api/get-users.json b/examples/github-user-api/get-users.json new file mode 100644 index 0000000..20962d7 --- /dev/null +++ b/examples/github-user-api/get-users.json @@ -0,0 +1,36 @@ +{ + "request":{ + "url": "/users", + "method" : "GET" + + }, + "response":{ + "status": 200, + "body": [ + { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + } + ] + , + "headers":{ + "Content-Type":"application/json" + } + } +} \ No newline at end of file diff --git a/examples/github-user-api/patch-user.json b/examples/github-user-api/patch-user.json new file mode 100644 index 0000000..3ad6c9c --- /dev/null +++ b/examples/github-user-api/patch-user.json @@ -0,0 +1,61 @@ +{ + "request":{ + "url": "/user", + "method" : "PATCH", + "body":{ + "name":"La Gioconda" + } + }, + "response":{ + "status": 200, + "body": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false, + "name": "La Gioconda", + "company": "GitHub", + "blog": "https://github.com/blog", + "location": "San Francisco", + "email": "octocat@github.com", + "hireable": false, + "bio": "There once was...", + "twitter_username": "monatheoctocat", + "public_repos": 2, + "public_gists": 1, + "followers": 20, + "following": 0, + "created_at": "2008-01-14T04:33:35Z", + "updated_at": "2008-01-14T04:33:35Z", + "private_gists": 81, + "total_private_repos": 100, + "owned_private_repos": 100, + "disk_usage": 10000, + "collaborators": 8, + "two_factor_authentication": true, + "plan": { + "name": "Medium", + "space": 400, + "private_repos": 20, + "collaborators": 0 + } + }, + "headers":{ + "Content-Type":"application/json" + } + } +} \ No newline at end of file diff --git a/examples/http-get-json-payload.json b/examples/http-get-json-payload.json deleted file mode 100644 index 826b1cc..0000000 --- a/examples/http-get-json-payload.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "request":{ - "url": "/user", - "method" : "GET" - - }, - "response":{ - "status": 200, - "body": { - "login": "octocat", - "id": 1, - "node_id": "MDQ6VXNlcjE=", - "avatar_url": "https://github.com/images/error/octocat_happy.gif", - "gravatar_id": "", - "url": "https://api.github.com/users/octocat", - "html_url": "https://github.com/octocat", - "name": "monalisa octocat", - "company": "GitHub", - "blog": "https://github.com/blog", - "location": "San Francisco", - "email": "octocat@github.com", - "plan": { - "name": "Medium", - "space": 400, - "private_repos": 20, - "collaborators": 0 - } - }, - "headers":{ - "Content-Type":"application/json" - } - } -} \ No newline at end of file diff --git a/examples/http-post.json b/examples/http-post.json index ca348d0..990e6b1 100644 --- a/examples/http-post.json +++ b/examples/http-post.json @@ -3,7 +3,6 @@ "url": "/tell-me", "method" : "POST", "body": "Some message" - }, "response":{ "status": 200, diff --git a/examples/response-with-json-payload.json b/examples/response-with-json-payload.json new file mode 100644 index 0000000..a7583cf --- /dev/null +++ b/examples/response-with-json-payload.json @@ -0,0 +1,18 @@ +{ + "request":{ + "url": "/json-response", + "method" : "GET" + + }, + "response":{ + "status": 200, + "body": { + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif" + }, + "headers":{ + "Content-Type":"application/json" + } + } +} \ No newline at end of file diff --git a/examples/simple-http-get.json b/examples/simple-http-get.json index af9d6ea..64f3ca9 100644 --- a/examples/simple-http-get.json +++ b/examples/simple-http-get.json @@ -2,13 +2,9 @@ "request":{ "url": "/ping", "method" : "GET" - }, "response":{ "status": 200, - "body": "pong", - "headers":{ - "Content-Type":"text/plain" - } + "body": "pong" } } \ No newline at end of file