[feature-request]: Use HTTP method as filename for an API endpoint to delegate HTTP request method #44909
        Labels
        
  
            
              template: story
  A user has filled out a feature request template. Will be converted to Discussions (Idea) 
        
      
Describe the feature you'd like to request
It'd would be nice to use HTTP methods as a filename scheme when creating API endpoints and be called based on the request type made by the client
Currently
Lets say we have two endpoints created, each will be handling
GETandPOSTrequests.The file directory would look like so
The API endpoint URL would be:
api/barapi/fooThen that would mean
bar.tsandfoo.tswill have code handlingGETandPOSTrequest in those files.foo.ts
bar.ts
There's seem to be redundant code to handle different HTTP method types.
So instead, it would be better to have API endpoint file changed to a folder and the files in that folder contain HTTP method as files that API will call depending on the request type made by the client.
Describe the solution you'd like
What I'm proposing is to split them based on HTTP methods
The API endpoint URL would be:
api/barapi/fooapi/foobar/bazsending request would be the same as before.
But now code that handle
GETandPOSTrequests are separatedCheck for more: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
foo/GET.ts
foo/POST.ts
bar/GET.ts
bar/POST.ts
foobar/baz/GET.ts
foobar/baz/POST.ts
pros
cons
Describe alternatives you've considered
An alternative is for exporting certain functions that handle HTTP requests based on the HTTP method types
Ex:
api/fooendpointCheck for more: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
NextJS looks for certain named functions that will be called depending on the HTTP method used.
Ex: if
GETrequest is made, then functionhandleGetis called automaticallyEx: if
POSTrequest is made, then functionhandlePostis called automaticallyIf a HTTP method is used and there's no corresponding function to handle it will return an automatic error code
405The text was updated successfully, but these errors were encountered: