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

[feature]: Mock Server #1598

Open
baaart opened this issue Apr 14, 2021 · 13 comments
Open

[feature]: Mock Server #1598

baaart opened this issue Apr 14, 2021 · 13 comments
Labels
feature New feature or request

Comments

@baaart
Copy link

baaart commented Apr 14, 2021

Is there a plan to have mock server option in similar way as it is done in Postman?

It would be nice to have all in one testing tool (API testing + mocking APIs), I was looking for this option in hoppscotch, but i don't see it anywhere.

@liyasthomas
Copy link
Member

As of now, there's no such feature to create mock APIs from Hoppscotch. But would definitely consider this if there's a major request for this feature.

@liyasthomas liyasthomas added the feature New feature or request label Apr 14, 2021
@jatin33
Copy link

jatin33 commented Apr 15, 2021

this will be a great feature, if we try something like this https://mockend.com/
@liyasthomas any thoughts

@liyasthomas
Copy link
Member

@jatin33 thanks for your suggestion. I'll look into this asap.

@bhavukkalra
Copy link

bhavukkalra commented May 8, 2021

Hi @liyasthomas I, actually saw this request in the github externships.
Could you please clear a few queries of mine, as I would love taking up this in my Github Externships Proposal.

I actually had tried using json-server NPM package to replicate the same scenario as that of postman's MockServer Creation i.e Filling the Data for the Form for GET/DELETE/POST request to be handled followed up by entering the data in the form of key value pairs. Then storing the JSON file in local directory and then Exposing it via a Node Server. Do let me know If you would like to see the prototype on Heroku.

I wanted the architecture to store the references(id's) to the Endpoints(new collection name) sub-collection(which would be a JSON object of the key value pairs entered by the user) in an array within the document of the user who created the mock-server, Something like this

USER Doccument
"Endpoints" = [id1, id2, id3 ...] //References to the Endpoints Sub-Collection

But I couldn't find any resources or examples to implement this into fruition.(Or Am i looking at it the wrong way?)

I have already started working on this but would really love, if you could guide me on some Initial flow for implementing this the correct way as my current approach above seems unmaintainable to me(which could cause a load on Cloud Firestore)

@liyasthomas
Copy link
Member

Hi @bhavukkalra I'd love to see your mvp. Also, we're still refining the feature and it's architecture. We'll think about this and let you know.

@bhavukkalra
Copy link

Sorry for the late reply @liyasthomas, about the MVP(for what will be designed for Hoppscotch to incorporate MockServer).
Could you please go through the workflow(Tentative) and suggest If there are any ambiguities or corrections that can be made to allow code Reusability and Stability.
Tentative Architecture for MockServer

After The Above logic has been written, each request to a route can be handeled via, this piece of Code

router.route('/:id')
    .get(handle.getEndpoint)
    .post(auth.authenticate, handle.IncorporateChanges)
    .delete(auth.authenticate, handle.deleteObject)

Also Would that be OK if I made the above prototype/MVP using Basic HTML and NodeJS for rapid prototyping? Just to show the Proof of Concept. After that it can be Integrated to Hoppscotch(NuxtJS) or should I start with NuxtJS to begin with?

@juzhiyuan
Copy link

Hi, do we have a plan to support mocking POST request? e.g

  1. POST /users
  2. GET /users
  3. We could find the resource which is created in Step 1.

@liyasthomas
Copy link
Member

"Mock requests" feature has the highest priority in our roadmap. Thanks for your patience, please bear with us and expect a beta release of Mock server soon.

@juzhiyuan
Copy link

ya, and what should I do if I want to contribute to this feature?

@bhavukkalra
Copy link

It's Still a Work in Progress, The MVP Presented above was made from a different Tech Stack and Had lot of Flaws(Reasonable, as it was just for a Proof of Concept). So, We are trying to do things the right way by making use of the appropriate tech stack(Which sometimes takes time, but is best for the long run). We know that there are a lot of requests for this feature to got out, but give us a little time more time and I assure you something is cooking in the Backend and you will see it very soon😉.
About the Contributing stuff I am not currently not sure about it, but only @AndrewBastin and @liyasthomas can suggest it better than me. Cheers

@liyasthomas liyasthomas changed the title Mock Server [feature]: Mock Server Oct 2, 2022
@jerga
Copy link

jerga commented Nov 2, 2023

+1 to see this new feature in Hoppscotch

@codeasashu
Copy link

codeasashu commented May 22, 2024

UPDATE: I went ahead and created a very basic implementation of mocks (see commit 63fe3f8) . It uses a hardcoded spec file and serves the responses quite well. The only ceavet is that it won't work without openapi specs, which I am currently working on.

I've a little experience in this, while designing my openapi-designer. The basic idea is as follows:

  1. Generate an openapi documentation from given api spec. We'd need an openapi converter similar to insomnia's.
  2. Use spectral's prism to start a mock server out of given schema
  3. Add a mock mode inside hoppsoctch. During mock mode, for any requests, the baseurls will be automatically replaced with the mock urls. This will be quite simple if we use mock server as a proxy (or interceptor).
  4. The mock mode will only support 1 collection at any given time. In team configuration. It can be started/stopped by having a toggle button at each collection level. For simplicity, we can initially support to run only 1 mock at any given time in a workspace.

Good thing is the backend is already in nodejs, which will support npm tool out of the box, via its api. Same will be helpful validating that the user's documentation is upto date (wrt the apis they have in collection).

The only missing piece is the openapi spec generator (which will be pointless without response examples), for which we are still waiting.

@HppZ
Copy link

HppZ commented Jul 1, 2024

I need mock server in hopp, who else?

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

No branches or pull requests

8 participants