Skip to content

Commit

Permalink
Add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
enginyoyen committed Apr 8, 2021
1 parent cac0737 commit ca58bbd
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 40 deletions.
54 changes: 54 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -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
````
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"headers":{
"Content-Type":"text/plain"
},
"withDelay": 2000
"withDelay": 4000
}
}
16 changes: 16 additions & 0 deletions examples/github-user-api/get-authenticated-user-fails.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
61 changes: 61 additions & 0 deletions examples/github-user-api/get-authenticated-user.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"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"
}
}
}
20 changes: 20 additions & 0 deletions examples/github-user-api/get-user-hovercard.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
58 changes: 58 additions & 0 deletions examples/github-user-api/get-user.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"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"
}
}
}
36 changes: 36 additions & 0 deletions examples/github-user-api/get-users.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
61 changes: 61 additions & 0 deletions examples/github-user-api/patch-user.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"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"
}
}
}
33 changes: 0 additions & 33 deletions examples/http-get-json-payload.json

This file was deleted.

1 change: 0 additions & 1 deletion examples/http-post.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"url": "/tell-me",
"method" : "POST",
"body": "Some message"

},
"response":{
"status": 200,
Expand Down
18 changes: 18 additions & 0 deletions examples/response-with-json-payload.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Loading

0 comments on commit ca58bbd

Please sign in to comment.