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

Functionnal API #53

Open
nfroidure opened this issue Jun 2, 2017 · 2 comments
Open

Functionnal API #53

nfroidure opened this issue Jun 2, 2017 · 2 comments

Comments

@nfroidure
Copy link

I'd really like to be able to use this module by just using its pure functions.

It is feasible by requiring those functions directly:

const preferredEncodings = require('negociator/lib/encoding');

Do you think it is safe or should we add a standard way to use those functions?

@dougwilson
Copy link
Contributor

Hi @nfroidure . Typically even though require allows you do do that, the danger of reaching into a module if it's not documented you can do so is that an internal file rearrangement can break you without warning (if you don't pin to a specific version).

The API of this module was created before I took over it and it does have a lot wanting in it. I think we could change the API if someone wanted to put together a proposal of what exactly they wanted the API to look like and the use-cases this would enable over the existing API 👍

@nfroidure
Copy link
Author

Thanks for your answer. I use this module here https://github.com/nfroidure/swagger-http-router/blob/master/src/lib.js#L3-L4

To build a extractResponseSpec function https://github.com/nfroidure/swagger-http-router/blob/master/src/lib.js#L79-L97

In this router, I choose to not use the built in req/res objects unlike in every major frameworks for several reasons (snapshot testing, functional programming, function composition over middlewares...). For that matter, the requests and responses are raw JSON serializable objects so I cannot use APIs that expect a regular NodeJS response object (here is a more complete explanation of the why https://github.com/nfroidure/swagger-http-router#goal ).

I guess that the extractResponseSpec could be used with little changes to provide a functional API in this module.

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