-
Notifications
You must be signed in to change notification settings - Fork 49
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
templated links + plural endpoints #416
Conversation
router uses templated links endpoints plural
@@ -123,7 +123,7 @@ export default { | |||
}, | |||
methods: { | |||
invite (user, role) { | |||
this.api.post('/camp-collaboration', { | |||
this.api.post('/camp-collaborations', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noch extremer ist es hier...
Beim erstellen neuer Objekte werden wir den Endpunkt immer angeben müssen...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aktuell könnte man das aber so lösen:
this.api.post(this.camp.camp_collaborations(), { ... })
Fast noch etwas schöner wäre es aber wenn wir den Store abändern, sodass folgendes möglich ist:
this.camp.camp_collaborations().post({ ... })
Dann wäre aber post
ein reserviertes Wort, so dürfte dann keine Relation mehr heissen. Alternativ:
this.camp.camp_collaborations()._meta.post({ ... })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gute Idee. Innerhalb von Vue ist das $
relativ weit verbreitet bzw. schon fast eine Konvention:
this.camp.camp_collaborations().$post({ ... })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ich verstehe die Idee nicht ganz.
CampCollaborations wird bereits als Embedded-Collection auf dem Camp mitgeliefert.
Wir kennen die Collection-URI somit nicht, sondern nur alle gelieferten CampCollaborations-Entity-URIs.
{
"id": "9cd0d827",
"name": "Camp 1",
"title": "Sommerlager",
"motto": "Camp 1 Motto",
"_embedded": {
"creator": { ... },
"camp_type": { ... },
"camp_collaborations": [
{
"_links": {
"self": {
"href": "http://localhost:8888/api/camp-collaborations/6a62ba05"
}
}
},
{
"_links": {
"self": {
"href": "http://localhost:8888/api/camp-collaborations/6f7851cb"
}
}
}
],
"periods": [ ... ],
"event_categories": [ ... ],
"eventCategories": [ ... ]
},
"_links": {
"self": {
"href": "http://localhost:8888/api/camps/9cd0d827"
},
"events": {
"href": "http://localhost:8888/api/events?camp_id=9cd0d827"
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Das ist wahr, aber ich habe vor einigen Wochen im hal-json-normalizer für genau solche Fälle die Möglichkeit hinzugefügt, einen self link für eine embedded list anzugeben. Also wäre die Lösung hier, einfach noch zusätzlich in _links
die URI für camp_collaborations
anzugeben (plus beim Normalizer die Option embeddedStandaloneListKey: 'items'
zu setzen). Dann wird die embedded List komplett standalone verwendbar, inklusive POST requests da rein.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool
Habe die API angepasst...
Resultat sieht jetzt so aus:
{
"id": "1be066e5",
"name": "Camp 2",
"title": "Camp 2 Title",
"motto": "Camp 2 Motto",
"_embedded": {
"creator": { ... },
"camp_type": { ... },
"camp_collaborations": [
{
"_links": {
"self": {
"href": "http://localhost:8888/api/camp-collaborations/d29e6221"
}
}
}
],
"periods": [ ... ],
"event_categories": [ ... ],
"eventCategories": [ ... ]
},
"_links": {
"self": {
"href": "http://localhost:8888/api/camps/1be066e5"
},
"camp_collaborations": {
"href": "http://localhost:8888/api/camp-collaborations?camp_id=1be066e5"
},
"events": {
"href": "http://localhost:8888/api/events?camp_id=1be066e5"
}
}
}
Ich habe die Client-Side jedoch nicht zum laufen gebracht... konnte den Link für die Camp-Collaboration-Collection nicht finden....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.camp.camp_collaborations._meta.self
bzw. this.api.href(camp, 'camp_collaborations')
müssten beide gehen, sonst funktioniert etwas noch nicht so wie ich es mir vorstelle
@pmattmann Brauchst du hier nochmals ein Review oder gibts noch etwas von deiner Seite her zu tun? |
Merged in Core Meeting |
router uses templated links
endpoints plural