Welcome Guest, Not a member yet? Register   Sign In
RESTful Sub Resource Handling Url
#1

(This post was last modified: 10-19-2020, 11:45 AM by paliz.)

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'); 
=> contactfile is sub Resource  
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) {
  
    return this.http.get('http://localhost:8080/contact/1' + id).pipe(map((info: any) => {
     // console.log(info);
      return info.data;
    }),switchMap((info: any) => {
      // console.log(info);
      return this.http.get('http://localhost:8080/contact/1/contactfile/1');
    }), catchError(error => {
      console.log(error);
      return throwError('erors');
    }));
  }





please help me  thnak ci funs
Enlightenment  Is  Freedom
Reply


Messages In This Thread
RESTful Sub Resource Handling Url - by paliz - 10-19-2020, 11:43 AM
RE: RESTful Sub Resource Handling Url - by paliz - 10-22-2020, 09:56 AM
RE: RESTful Sub Resource Handling Url - by paliz - 10-23-2020, 07:38 AM
RE: RESTful Sub Resource Handling Url - by paliz - 10-25-2020, 04:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB