Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Programmatic API #49

Closed
katsanva opened this issue Apr 1, 2018 · 5 comments
Closed

Programmatic API #49

katsanva opened this issue Apr 1, 2018 · 5 comments
Projects

Comments

@katsanva
Copy link
Contributor

katsanva commented Apr 1, 2018

Hi @nmaro. What about to have programmatic API for ooth alongside HTTP?

That will allow creating ooth-based services that can communicate not only by HTTP, but any transporter (e.g WebSocket, RabbitMQ, NATS, etc) and with the power of any framework (e.g. seneca, moleculer, sails, koa, etc.).

In this way, current HTTP API, which is now hard tied to express, may become an express router which uses programmatic API internally.

As far of now I can't find any way to integrate ooth with some existing code base than make fetch/request to ooth's HTTP endpoint, and that looks like a pretty strange (and expensive in latency) solution.

@aaronmgdr
Copy link
Contributor

I like this

@nickredmark
Copy link
Owner

Good idea.

@nickredmark nickredmark added this to Prioritized in Ooth Apr 6, 2018
@nickredmark
Copy link
Owner

Hey @katsanva since I believe this will generate a major release I think we need to discuss the details a bit more.

Ooth is coupled to express, because it is coupled to passport.js which injects the user in the request and session. I think I need a better idea of where you want to make the decoupling cut. Could give some examples of

  • methods that you would like to call on such a programmatic API (and what they would do).
  • What you would give to the ooth constructor instead of an express app.

A note: the express app provided to ooth is used to

  • register a few global middlewares (cookieParser, bodyParser, passport and expressWs)
  • register express.Router to which all routes are registered (methods called are all, get, ws, post).

@nickredmark nickredmark moved this from Prioritized to Doing in Ooth Apr 6, 2018
@katsanva
Copy link
Contributor Author

katsanva commented Apr 9, 2018

Hey, @nmaro

Its all about to decouple oooh from express and HTTP protocol only.

The idea is to make same API to HTTP one, like POST /local/register -> ooth.local.register() and so on. Going this way to create an instance you need only to define what strategies should ooth use and what backend for users to use.

It may be the best way to re-use passport strategies without actual passport.js usage.

The express usage may persist in some ooth-express package, which will only call ooth.local.register() and so on under the hood.

@nickredmark
Copy link
Owner

Now every method registered with

ooth.registerMethod can be called with ooth.callMethod

For example with ooth-local it is now possible to run

ooth.on('register', ({_id, email, verificationToken}) => ...))

await ooth.callMethod('local', 'register', { email, password })

If this doesn't satisfy all your use cases just let me know, I'll close this for now.

@nickredmark nickredmark moved this from Prioritized to Done August 2018 in Ooth Aug 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Ooth
Done August 2018
Development

No branches or pull requests

3 participants