Tuesday 15 February 2022

Angular 10 + API service call key notes

 


Things to Angular Service calls:


1. Do we need state management or not . if we need then the API calls goes with effects concept.

2. Consider HTTP interceptors. Are we using any JWT to pass Bearer <Token> on every request.

3. Advanced is to create the model(interface or class) for each response and parse them and send to component. Simple is to parse the HTTPresponse and get data from body. 


4. Normal way is to make the api call in service ->  fetch the data(Observable)  -> 

pass it to pipe -> do the map() and parse the data -> return to component. 



5.Depends on the data to show: ex: menu1 api=> /api/menu1 


say if it has only htmlText then below is the one. BY default  HTTP error interceptor will parse each response to see the response status is 200 (success) , 401(unauthorized)  , 403(forbidden) , 500(internal server ) and handle them accordingly..


{

'id':1,

'name': 'Yuv'

}



6. if data is array then consider :  


[ {

'id':1,

'name': 'Yuv'

}, {

'id':2,

'name': 'Raj'

}]

No comments:

Post a Comment