Giter Site home page Giter Site logo

REST Methods about goweb HOT 5 CLOSED

pattmax00 avatar pattmax00 commented on June 20, 2024
REST Methods

from goweb.

Comments (5)

tfasano1 avatar tfasano1 commented on June 20, 2024 1

Big help! Thanks

from goweb.

tfasano1 avatar tfasano1 commented on June 20, 2024

The gorilla mux looks like a solution, but maybe we can get away with enabling CORS requests on the web server? Let me know any input you have.

https://code.whatever.social/questions/46310113/consume-a-delete-endpoint-from-go

from goweb.

pattmax00 avatar pattmax00 commented on June 20, 2024

I think you have to make PUT and DELETE requests with fetch
https://stackoverflow.com/a/68529248
I will look into CORS

from goweb.

tfasano1 avatar tfasano1 commented on June 20, 2024

As far as the backend / middleware goes, should delete routes / controllers be in their own go files? I've tried supporting multiple methods on handles /users/{id} (sending DELETE would delete the user, sending PUT to that same url would update the user's info) but in the current setup of this project each url handle is limited to one http method.

I'm aware you can sort of achieve what I'm trying to do by switching on the request method, like this https://git.sr.ht/~m15o/midnight-pub/tree/master/item/ui/post_remove.go , but in this framework handlers are segregated by http method into separate controller files. Is there an intended work-around for this issue ?

from goweb.

pattmax00 avatar pattmax00 commented on June 20, 2024

New controller files should be named and created according to their purpose like userController.go I should change this and make it more clear in the default setup.

For routes, I suggest having a couple big master files, so it's easy to find the logic associated with them (eg. user reports an error on page /url/thing/example).

So for your use case I'd say make a new routes file called multiMethodRoutes.go (or whatever name you find better) and those can be tied to Go functions that are tied to a switch statement like in the example you gave (the controllers these functions exist in should just be grouped by use case, so it's fine to have a controller with functions for GET, POST, PUT, and DELETE requests if needed). It's really all just a naming convention though, you could define these routes in getRoutes.go or postRoutes.go but that would be improper.

Hopefully this all makes sense.

from goweb.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.