Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support other Content-Types #31

Open
turicas opened this issue Oct 11, 2014 · 4 comments
Open

Support other Content-Types #31

turicas opened this issue Oct 11, 2014 · 4 comments

Comments

@turicas
Copy link

turicas commented Oct 11, 2014

Hello,

I'd like to use interfake to simulate an API I'm implementing but I think I can't use more than one Content-Type for the same HTTP resource. In my case, I'd like to answer the same data but in different formats, depending on Accept header sent by client -- this is needed because some of my API clients use msgpack to serialize data and others simply use JSON.

I've done a quick look into interfake's code but as I'm new to nodejs world, I didn't start implementing this feature by now, but I think we'll need to modify expectationsLookup and Route.simpleHash to implement this feature. What do you think?

Note: thanks for writing this awesome project! :)

@basicallydan
Copy link
Owner

Hey @turicas thanks for the suggestion. I think it's a sensible one, not entirely how I'd approach implementing it though.

I was a bit hesitant because I don't want to expand Interfake's scope too much but I can see how it could be useful, and fairly simple to change the response format.

For msgpack especially, it might be possible to simply use this encoder/decoder, msgpack-js as some kind of middleware for the body.

I'm all for it! You're welcome to give it a go if you like, but for now I'll put a looking-for-contributor label on it. If you get to it, say so, but if not I'll give it a go unless someone else does!

@turicas
Copy link
Author

turicas commented Oct 14, 2014

@basicallydan, first of all, thanks! :-)

One possible solution is to create a http-proxy on top of Interfake that does all the content-type thing, so we don't need to modify Interfake internals.

Unfortunately by now I don't enough time and knowledge on NodeJS/Express to do it quickly.

@basicallydan
Copy link
Owner

@turicas No prob!

Would that http-proxy module work for the case you're talking about? It sounds like the data would need to be transformed, and it might be easy enough to do it within Interfake. If http-proxy can do it without changing how the data is stored in memory then it should be just a matter of detecting the accept header type and transforming it. Does that sound about right?

@turicas
Copy link
Author

turicas commented Oct 16, 2014

Yep! The idea is to put on the proxy module the responsability on detecting the Accept header and serializing (from JSON) to other formats if needed before delivering the response to the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants