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

Singular Resources #256

Open
brentmurphy opened this issue Jul 25, 2016 · 4 comments
Open

Singular Resources #256

brentmurphy opened this issue Jul 25, 2016 · 4 comments

Comments

@brentmurphy
Copy link

Hi,

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

/api/users/:id/settings
@sharpner
Copy link
Member

sharpner commented Jul 25, 2016

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
Copy link
Author

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
Copy link
Member

wwwdata commented Jul 25, 2016

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
Copy link
Member

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..

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

No branches or pull requests

3 participants