RESTful Sub Resource Handling Url |
hi let jump in the problem
i m writing Restful Api beck end With Ci4 if have two controller extend from ResourceController contact And ContactFile how manger URL for sub Resuoures http://api.example.com/contact /* get*/ http://api.example.com/contact /* post*/ http://api.example.com/contact/{id} /* put*/ http://api.example.com/contact/{id} /*delete */ this code is user for contactController PHP Code: $routes->resource('contact'); i need these urls bellow according to restful api rules http://api.example.com/contact /{id}/contactfile* get*/ http://api.example.com/contact /{id}/contactfile* post*/ http://api.example.com/contact/{id} /contactfile{id}/* put*/ http://api.example.com/contact/{id} /contactfile/{id}/*delete */ and this code is no good for sub resource Code: $routes->resource('contactfile'); this is work but not best way handle request it need two time request for one for Parent(contactCtl) then childern(contacFileCtl) here is code with angular 10 Get Http Request its nested request Code: public getSingelPost(id: number) { please help me thnak ci funs
Enlightenment Is Freedom
i find way to manage nested resource
first go to this link https://restfulapi.net/resource-naming/ to understand restful api then decide what you want to follow . i think its up to you which way to go no nested vs nested here`s my code PHP Code: $routes->group('api', ['namespace' => 'App\Controllers\Api'], function ($routes) {
Enlightenment Is Freedom
I think with new define:
- only one url: yoursite.com/api/v1 - only one POST request - define data post: - ------ type [get, put, patch, list, sort, add, delete,... anything you want] - ------ data,... On your api controller handle, map type with function, then process and return,... Learning CI4 from my works, from errors and how to fix bugs in the community Love CI & Thanks CI Teams
Only one route post
Learning CI4 from my works, from errors and how to fix bugs in the community Love CI & Thanks CI Teams
You can define data post with id,... anything
Learning CI4 from my works, from errors and how to fix bugs in the community Love CI & Thanks CI Teams |
Welcome Guest, Not a member yet? Register Sign In |