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

Creating a related resource #257

Open
arcijsg opened this issue Aug 11, 2016 · 2 comments
Open

Creating a related resource #257

arcijsg opened this issue Aug 11, 2016 · 2 comments
Labels

Comments

@arcijsg
Copy link

arcijsg commented Aug 11, 2016

First of all, thanks for the great library - it's nice to see how this project evolves and how responsive the authors are.
For me it is a good example on how to drive a small open-source project.

Moving on to the question - i'm creating a simple invoicing api, where we have three main resources:
/invoices - is the main, self-sufficient resource:
client creates an empty invoice draft by POSTing to /invoices, and then slowly adds details (line items (/lines resource) and /discounts) one by one;

The later two: /lines and /discounts - are not meaningful without the invoice.
So, i found myself wishing to be able to create the following endpoints:

POST /invoices/<id>/lines
POST /invoices/<id>/discounts

where a line items and discounts for the invoice drasft can be added.
Currently, if foud no way on how to create such endpoints for dependent resources without creating custom handler and losing all the goodness the api2go.CRUD handlers provide.

I see that the easiest solution would be to post to /lines and /discounts directly, and provide linkage with the invoice in payload,
under the "relationships" section, for example:

{
  "data": {
    "type": "lines",
    "attributes": {
      "description": "Mostest bestest Everest",
      "quantity": 1,
    }
  },
  "relationships": {
    "invoice": {
      "data": { "type": "invoices", "id": "121" }
    }
  }
}

I might go that way, however, i'd like to ask what do you guys think about making available such endpoints for dependent resources?

Would it be hard to implement in addResource, or would it be against the spirit behind this library, or not in line of jsonapi.org specification at all (although i could not find anything like that yet in the specification or discussions)?

@sharpner
Copy link
Member

hey :) glad you like the library!

We are already thinking about integration of custom subroutes, but have not yet found a clever way to do this.

The issues #244 #256 are already waiting for it, so we will support it somewhere in the future, but it might take a while :)

If you have an idea, feel free to send us a PR!

@arcijsg
Copy link
Author

arcijsg commented Aug 11, 2016

Thanks for the quick response!

I'm afraid i still have too little knowledge on how to properly program in Go to do a contribution yet, but i'm really looking forward to the solution :)

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

No branches or pull requests

2 participants