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

Add dispatching based on headers #549

Open
imod opened this issue Jan 22, 2022 · 8 comments
Open

Add dispatching based on headers #549

imod opened this issue Jan 22, 2022 · 8 comments

Comments

@imod
Copy link
Contributor

imod commented Jan 22, 2022

In my experience, most of the APIs do provide a way to retrieve a collection of items - even if I create a dynamic mock with microcks, i get an endpoint to collect all saved items. These endpoints mostly don't have any changing part in the URI.
If these items are not globally available for e.g. all user or depend on any other input passed with a header information, then I'm out of luck.

Common scenarios I see:

  • the user to get the information for is passed as a clear string in a header
  • where location information is added to the request by an intermediate proxy as a header

Sure in many cases the user is passed as a JWT, but not always.
In these cases the headers are the only arguments to get the relevant information and I think this should be made as easy as possible - specially as it is so simple to define these in e.g. the postman collection and import them.

@imod
Copy link
Contributor Author

imod commented May 3, 2022

@lbroudoux would this be something for a contribution? If yes, can you point me into the right direction? :)

@lbroudoux
Copy link
Member

lbroudoux commented May 3, 2022

Hi @imod!

This could be a great contribution! Definitely. I'll try to give you some hints for bootstrapping it.

Basically, you'll have to consider 2 things:

  • The importer part that takes care of parsing input artifact to fill the Microcks Service/Operation/Messages models with dispatching informations,
  • The mock engine that takes care of incoming requests, checks their variables parts (path, query params and nos headers) and find out the appropriate response depending on dispatching rules.

Importer part

The main interface here is MockRepositoryImporter that defines the visited methods when parsing and importing an input artifact. There's of course different implementations for OpenAPI, Swagger or Postman and that's where you'll have to add specific new dispatching rules for headers. See https://github.com/microcks/microcks/blob/master/webapp/src/main/java/io/github/microcks/util/postman/PostmanCollectionImporter.java#L476 for example.

One important thing to notice is that during import you have to find dispatcherRules for operation but also dispatchCriteria for each response (this is kinda like a hash that later helps retrieving correct response). See https://github.com/microcks/microcks/blob/master/webapp/src/main/java/io/github/microcks/util/postman/PostmanCollectionImporter.java#L201 for example.

Mock engine part

Now the second part is to implement actual routing for incoming requests on mocks. This has to be done into the RestController class for REST API mocks. The main duty of such controller is to identify Service/Operation call and then recompute the dispatchCriteria with request variables parts. See https://github.com/microcks/microcks/blob/master/webapp/src/main/java/io/github/microcks/web/RestController.java#L175 for how it is done. It's typically there that you'll have to integrate your new dispatching logic based on headers.

Hope it helps. Do not hesitate for further assistance.

@lbroudoux
Copy link
Member

Hey @imod! Is it still something you're considering for a contribution?

@imod
Copy link
Contributor Author

imod commented Jun 7, 2022

I would love to do so yes, but I just did not find the time yet - if your faster then I am, please feel free :)
but one of the problems I might face is the fact, that i currently only know some of the import formats/tools e.g. I don't know SOAP UI or GraphQL...

@lbroudoux
Copy link
Member

Thanks for quick reply. Dispatcher do not have to be implemented for all protocols. Regarding headers, I don't know if they make sense in the case of Soap of GraphQL... You can start with just one REST implementation and then we'll see 😉

@lbroudoux lbroudoux added this to the 1.6.0 milestone Jun 10, 2022
@lbroudoux lbroudoux modified the milestones: 1.6.0, Next Sep 9, 2022
@lbroudoux lbroudoux modified the milestones: 1.7.0, Next Mar 6, 2023
@lbroudoux
Copy link
Member

Hey @imod! How are you doing?
I think that unfortunately, we will have to shift that one again. Is there still something you're interested in?
Please let me know what could be the priority on this one.

@lbroudoux lbroudoux modified the milestones: 1.7.1, Next Jun 8, 2023
@lbroudoux lbroudoux changed the title dispatch based on headers Add dispatching based on headers Jun 8, 2023
@lbroudoux lbroudoux modified the milestones: 1.8.0, 1.8.1 Oct 10, 2023
@lbroudoux
Copy link
Member

lbroudoux commented Oct 10, 2023

Hi @imod! We're shifting this one for other priorities. Is this something still of interest to you?
Is there anyone out there that still has this need or is interested in contributing to it?

cc @redben, @espositogiacomo, @AryanaAgustavo

@lbroudoux lbroudoux modified the milestones: 1.8.1, 1.9.0 Jan 5, 2024
@lbroudoux lbroudoux modified the milestones: 1.9.0, 1.9.1 Mar 12, 2024
Copy link

github-actions bot commented May 3, 2024

This issue has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. Microcks is a Cloud Native Computing Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️

@github-actions github-actions bot added the stale State due to inactivity label May 3, 2024
@lbroudoux lbroudoux added keep-open Explicitily keep open and removed stale State due to inactivity labels May 14, 2024
@lbroudoux lbroudoux modified the milestones: 1.9.1, 1.10 May 14, 2024
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