maitria/mock-api-server

Responding to different HTTP methods.

Closed this issue · 3 comments

I'd like to understand an approach we have in mind for responding to different HTTP methods. Any ideas?

I've been thinking–for the canned responses, at least–that we put the method in the filename similar to the query strings. For example:

test/mock-api/v2/foo/bar.json
test/mock-api/v2/foo/post,bar.json
test/mock-api/v2/foo/delete,bar.json
test/mock-api/v2/foo/put,bar.json

I'm not sure whether I like the ability to put make a file named get,bar.json. It seems necessary for completeness, but allows people to make two files which match identical criteria.

Hrmm, but that's possible anyway.

Cool. Without the HTTP verb, the file's path does a good job of mimicking the request path. I wonder if jamming the HTTP verb into the filename dilutes that expressiveness.

Thoughts on specifying the verb as part of the path itself?

eg,

test/mock-api/GET/v2/foo/bar.json
test/mock-api/PUT/v2/foo/bar.json
test/mock-api/POST/foo/bar.json

@drtangible Good call. I like that.

We can use the query string for POST and PUT and such, too. Which just leaves cookies. Don't know how to handle those if/when we need to.