Question: Different I/O for different methods
See original GitHub issueHi,
I’ve started trying to use this module to manage my endpoints since I love the philosophy of how it’s setup. I have a question about a use case.
For an endpoint with multiple methods (i.e. post
and get
) is it possible to have an input and output for post
that is different than the input and output for get
? Or, I guess a way to attach different endpoint definitions to the same route would also work?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
I/O Control Methods: Types & Explanation - Study.com
The interrupt-based I/O method controls the data transfer activity to and from connected I/O devices. It allows the CPU to continue to process ......
Read more >Operating Systems: I/O Systems
Another technique for communicating with devices is memory-mapped I/O. ... A potential problem exists with memory-mapped I/O, if a process is allowed to ......
Read more >Memory mapped I/O and Isolated I/O - GeeksforGeeks
There are three ways in which system bus can be allotted to them : Separate set of address, control and data bus to...
Read more >8.4 Different Types of Questions
Interviewers are most likely to ask one of four types of questions: Open-ended questions; Specific questions; Motivation questions; Unconventional questions.
Read more >Lesson: Basic I/O (The Java™ Tutorials > Essential Java ...
This lesson covers the Java platform classes used for basic I/O. It first ... Other Useful Methods covers important API that didn't fit...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I looked it over and, this seems like a great solution. If I understand correctly, it allows a complete endpoint definition for each method on a specific route. That would let someone have specific input and output schemas, which clearly solves this problem, but it should also allow specific middleware or even a specific result handler to be configured for each method, which is great, since that enables maximum flexibility while maintaining the simplicity of the endpoint definitions.
What I ended up doing, for now, was something similar to the suggestion 2. I set the input schema to be an empty object with passthrough enabled, then I used the method middleware to determine the method, then I parsed the input separately for each method. This is a little bit of a janky workaround, but it does get the job done! I haven’t started working on the OpenApi docs yet, but being able to automatically generate documentation for the endpoints would be really nice, and it looks like this tool can do that too! I would assume that these workarounds would make the documents less helpful though, and defining specific inputs and outputs for each method would allow the docs to also show those details, which would be great!
Just to give you some more background info, here’s the general way we have our endpoints setup.
POST: /v1/users
This returns the object that was posted (plus any meta data such as the database id)GET: /v1/users?name=jane%20doe
This returns a list of the objects. These two cases already create a need for the different IO schemas.DELETE: /v1/users/1
The DELETE method would use the 204 status code, which would have no body on the response, and the PUT and PATCH methods would return the full item with meta data.{ body: string, headers: Record<string, string> }
and then I have a specific response handler to return it properly. I’m not sure how the OpenAPI parser would handle that, but it would be nice to be able to either set the output schema to simply be a string and then have another method for setting the headers (possibly just a middleware that makes a function available to the endpoint to set them, or a more general way to pass meta data to the response handler) or to be able to specify a key on the output schema that is used to define the actual output schema when generating the documentation.So, our routing looks a little weird, but it works! Here’s how I set it up for one of our services:
Thanks again for getting back to me on this and for actually putting in the work on the PR. I really like how you’ve architected this library, and your solution does seem to be just as elegant. … Ps. If I do have some other use cases that come up, and I think it’s something I could tackle, I’d totally be willing to create a PR! This one seemed a little involved and I wasn’t sure if you were willing to open the tool up to be more generic or if you preferred to keep it more specific.
the feature released in version
1.2.0