RESTful Sub Resource Handling Url - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: RESTful Sub Resource Handling Url (/showthread.php?tid=77791) |
RESTful Sub Resource Handling Url - paliz - 10-19-2020 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 RE: RESTful Sub Resource Handling Url - paliz - 10-22-2020 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) { RE: RESTful Sub Resource Handling Url - nc03061981 - 10-23-2020 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,... RE: RESTful Sub Resource Handling Url - nc03061981 - 10-23-2020 Only one route post RE: RESTful Sub Resource Handling Url - paliz - 10-23-2020 (10-23-2020, 06:18 AM)nc03061981 Wrote: Only one route posti almost finished api and i test with postman it need other route too . post function is not enough for curd restful api RE: RESTful Sub Resource Handling Url - nc03061981 - 10-23-2020 You can define data post with id,... anything RE: RESTful Sub Resource Handling Url - paliz - 10-25-2020 (10-23-2020, 06:09 PM)nc03061981 Wrote: You can define data post with id,... anythingyes i use id and restful api recommend use id too today i finished backend after i make sure every thing work i ll start to do front end with angular 10 |