Skip to content

Commit

Permalink
Rename-upsert (#154)
Browse files Browse the repository at this point in the history
* todo list

* fix path

* fix ui

* rename update to upsert
  • Loading branch information
jackkav authored Jan 10, 2024
1 parent 14b87d2 commit f0b23c2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,17 @@ Editor preferences are available in the [editor config](.editorconfig) for easy
[npm-version]: https://img.shields.io/npm/v/mockbin.svg?style=flat-square
[gitter-url]: https://gitter.im/Kong/mockbin
[gitter-image]: https://img.shields.io/badge/Gitter-Join%20Chat-blue.svg?style=flat-square

## TODO

- [x] update node
- [x] github action
- [x] autofix on save
- [x] upsert bin endpoint
- [x] simplify entrypoint and environment
- [x] replace unirest with fetch
- [ ] redis function binding
- [ ] callback tests
- [ ] bin tests
- [ ] support method as parameter
- [ ] wild cards in url
9 changes: 4 additions & 5 deletions docs/api/bins.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Responds with a `Location` header with the newly created **Bin**, e.g. `Location
- HTTP headers *(e.g. `X-My-Header-Name: Value`)*
- body content *(max of 100mb)*
- query string *(e.g. `?foo=bar`)*
- path arguments *(e.g. `/bin/3c149e20-bc9c-4c68-8614-048e6023a108/any/extra/path/`)*
- All requests to Bin will be [logged](#view-logs) for later inspection *(max of 100 requests)*

###### Request
Expand Down Expand Up @@ -91,18 +90,18 @@ Responds with a `Location` header with the newly created **Bin**, e.g. `Location
----
#### Update Bin
#### Upsert Bin
> ##### `PUT /bin/:id/a/b/c`
> ##### `PUT /bin/upsert/:id/a/b/c`
Creates or updates a **Bin** with a mock HTTP response as described by a [HAR Response Object](http://www.softwareishard.com/blog/har-12-spec/#response) body. /a/b/c represeent any following paths than will be combined with the id for response matching.
Creates or replaces a **Bin** with a mock HTTP response as described by a [HAR Response Object](http://www.softwareishard.com/blog/har-12-spec/#response) body. /a/b/c represeent any following paths than will be combined with the id for response matching.
Responds with a `Location` header with the updated **Bin**, e.g. `Location: /bin/3c149e20-bc9c-4c68-8614-048e6023a108/a/b/c` *(the Bin ID is also repeated in the body)*
###### Request
> ```http
> PUT /bin/3c149e20-bc9c-4c68-8614-048e6023a108/a/b/c HTTP/1.1
> PUT /bin/update/3c149e20-bc9c-4c68-8614-048e6023a108/a/b/c HTTP/1.1
> Host: mockbin.org
> Content-Type: application/json
> Accept: application/json
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/bins.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = function bins(dsnStr) {
path: "/delete/:uuid*",
route: routes.delete.bind(this),
},
{ action: "put", path: "/:uuid*", route: routes.update.bind(this) },
{ action: "put", path: "/upsert/:uuid*", route: routes.update.bind(this) },
{ action: "all", path: "/:uuid*", route: routes.run.bind(this) },
];

Expand Down
2 changes: 1 addition & 1 deletion lib/routes/bins/view.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const debug = require("debug")("mockbin");

module.exports = function (req, res, next) {
this.client.get(`bin:${req.params.uuid}`, (err, value) => {
this.client.get(`bin:${req.params.uuid + req.params[0]}`, (err, value) => {
if (err) {
debug(err);

Expand Down
6 changes: 3 additions & 3 deletions src/views/bin/log.pug
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ mixin method (method)
block content
div(data-page="bin/log").container
div.btn-group.pull-right.hidden-xs
a(href= '/bin/view/' + req.params.uuid).btn.btn-primary View Details
a(href= '/bin/view/' + req.params.uuid + req.params[0]).btn.btn-primary View Details

h3 Bin History: #[code= req.params.uuid]
h3 Bin History: #[code= req.params.uuid + req.params[0]]

div.visible-xs
a(href= '/bin/view' + req.params.uuid).btn.btn-block.btn-primary View Details
a(href= '/bin/view' + req.params.uuid + req.params[0]).btn.btn-block.btn-primary View Details

hr

Expand Down
8 changes: 4 additions & 4 deletions src/views/bin/view.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ block content
div(data-page="bin/view").container
div.row
div.col-sm-9
h3 Bin Identifier: #[code= req.params.uuid]
h3 Bin Identifier: #[code= req.params.uuid + req.params[0]]

div#preview
pre: code= data.json
Expand All @@ -13,14 +13,14 @@ block content
h3 Next Steps

a(href= '#apiembed').btn.btn-block.btn-primary #[span.badge 1]   Send Some Requests
a(href= '/bin/' + req.params.uuid).btn.btn-block.btn-primary #[span.badge 2]   Visit in Browser
a(href= '/bin/log/' + req.params.uuid).btn.btn-block.btn-primary #[span.badge 3]   View History
a(href= '/bin/' + req.params.uuid + req.params[0]).btn.btn-block.btn-primary #[span.badge 2]   Visit in Browser
a(href= '/bin/log/' + req.params.uuid + req.params[0]).btn.btn-block.btn-primary #[span.badge 3]   View History

br

h4#apiembed Send Some Requests:

p Send request to #[a(target="_blank", href=req.protocol + '://' + req.get('host') + '/bin/'+ req.params.uuid )= req.protocol + '://' + req.get('host') + '/bin/' + req.params.uuid ]
p Send request to #[a(target="_blank", href=req.protocol + '://' + req.get('host') + '/bin/'+ req.params.uuid + req.params[0] )= req.protocol + '://' + req.get('host') + '/bin/' + req.params.uuid + req.params[0] ]



Expand Down
2 changes: 1 addition & 1 deletion src/views/redirect.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ html
meta(http-equiv='refresh', content=`0; url=${res.getHeaders().location.replace('/bin','/bin/view')}`)

body
p Redirecting to #[a(href=res.getHeaders().location)= res.getHeaders().location.replace('/bin','/bin/view')]
p Redirecting to #[a(href=res.getHeaders().location.replace('/bin','/bin/view'))= res.getHeaders().location.replace('/bin','/bin/view')]

0 comments on commit f0b23c2

Please sign in to comment.