Quantcast

API Design using CakePHP 3

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

API Design using CakePHP 3

Rafael Queiroz
Hi guys,

I make a API using CakePHP 3.2.x, so, and now have a angular app requesting API.
My question is about association data, e.g. i have Series Model and send the request:

api.com/series/add

{
    "id": 5,
    "title": "New serie",
    "hidden": false,
    "courses": {"_ids":["1","2"]}
}

It's work, many times, i have problems, because first time in edit, i get register and mockup in scope of app, and have problems, because register have all fields, per sample:

1. Avoiding Mass Assignment Protection in Entity, because save created = null
2. Send all object data, have association data i don't want send, i need using transformRequest in angularJs
3. Many times i have problem with CORS, because send a object complex, not expected, if simple object it's work
4. I have problem for delete association data, have a garbage in docs, but not work's 100%. [1]

So, this easy save data and associations, now, it's my nightmare.

My point is about best practices for api, i read articles and have a solution, using sub resources.

I need create new endpoints for retrieve/save/delete associations data in register ?
What do you think ? Thank you in advance for your attention

[1] http://book.cakephp.org/3.0/en/orm/saving-data.html#patching-hasmany-and-belongstomany

--
Regards,

Rafael F. Queiroz

--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup
 
We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.
 
Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: API Design using CakePHP 3

Florian Krämer-2
1) I would not avoid that. We use the protection and have no problem at all with it.
2) Create a filter and use it in beforeSave()? Create data objects like the entities in Cake and filter the date there before sending?
3) No idea what you're talking about, you basically say "It's not working righ". We do the transformRequest just once AFAIR.
4) No idea, "It's not working" is nothing you'll get help with.

See http://book.cakephp.org/3.0/en/development/routing.html#creating-restful-routes There is also the FoC CRUD plugin but we don't use it yet and probably won't. Cake is good enough as it is for us so far. We're re-building our frontend and a CRM with Angular and Cake3.

On Wednesday, March 9, 2016 at 3:04:19 PM UTC+1, Rafael Queiroz wrote:
Hi guys,

I make a API using CakePHP 3.2.x, so, and now have a angular app requesting API.
My question is about association data, e.g. i have Series Model and send the request:

<a href="http://api.com/series/add" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fapi.com%2Fseries%2Fadd\46sa\75D\46sntz\0751\46usg\75AFQjCNG5E2xMO1H3U_rTM5iqSiyFA0npSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fapi.com%2Fseries%2Fadd\46sa\75D\46sntz\0751\46usg\75AFQjCNG5E2xMO1H3U_rTM5iqSiyFA0npSQ&#39;;return true;">api.com/series/add

{
    "id": 5,
    "title": "New serie",
    "hidden": false,
    "courses": {"_ids":["1","2"]}
}

It's work, many times, i have problems, because first time in edit, i get register and mockup in scope of app, and have problems, because register have all fields, per sample:

1. Avoiding Mass Assignment Protection in Entity, because save created = null
2. Send all object data, have association data i don't want send, i need using transformRequest in angularJs
3. Many times i have problem with CORS, because send a object complex, not expected, if simple object it's work
4. I have problem for delete association data, have a garbage in docs, but not work's 100%. [1]

So, this easy save data and associations, now, it's my nightmare.

My point is about best practices for api, i read articles and have a solution, using sub resources.

I need create new endpoints for retrieve/save/delete associations data in register ?
What do you think ? Thank you in advance for your attention

[1] <a href="http://book.cakephp.org/3.0/en/orm/saving-data.html#patching-hasmany-and-belongstomany" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fbook.cakephp.org%2F3.0%2Fen%2Form%2Fsaving-data.html%23patching-hasmany-and-belongstomany\46sa\75D\46sntz\0751\46usg\75AFQjCNHxVa4wtyx8WQmydeO-U6Dzi4wqPA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\75http%3A%2F%2Fbook.cakephp.org%2F3.0%2Fen%2Form%2Fsaving-data.html%23patching-hasmany-and-belongstomany\46sa\75D\46sntz\0751\46usg\75AFQjCNHxVa4wtyx8WQmydeO-U6Dzi4wqPA&#39;;return true;">http://book.cakephp.org/3.0/en/orm/saving-data.html#patching-hasmany-and-belongstomany

--
Regards,

Rafael F. Queiroz

--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup
 
We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.
 
Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...