manyminds / api2go

JSONAPI.org Implementation for Go
MIT License
696 stars 93 forks source link

Singular Resources #256

Open brentmurphy opened 8 years ago

brentmurphy commented 8 years ago

Hi,

Does api2go provide a way of handling singular resources? For example, a mapping to the following route:

/api/users/:id/settings
sharpner commented 8 years ago

You mean out of the jsonapi context? You can simply add custom route to your router/muxer.

        mux := http.NewServeMux()
        mux.HandleFunc("/blub", func(w http.ResponseWriter, r *http.Request) {
                fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
        })

        http.ListenAndServe(fmt.Sprintf(":%d", port), mux)

or you can cheat like this: https://github.com/manyminds/api2go/blob/master/examples/crud_example.go#L67

brentmurphy commented 8 years ago

Ok thanks. This is quite a common requirement for the project I'm currently working on (migrating from a Rails codebase). Is there anything in the roadmap for handling this kind of request, or is it just outside the scope of JSONAPI?

wwwdata commented 8 years ago

this is outside the JSONAPI scope. So like @sharpner said you can add stuff with your own routes as well. You can get the router instance and register your own routes on it as well http://godoc.org/github.com/manyminds/api2go#API.Router

sharpner commented 8 years ago

We are currently actually thinking about an easier way to create subroutes for objects because we need this for #244 . But I don't think it will come in the near future because we could not find a clean generic way yet..