Skip to main content

Posts

Showing posts with the label http request

Using NGXS actions instead of repeating API calls

Photo by Branko Stancevic on Unsplash    When you need to send an API call , be it GET, POST or any other http request call, you can incorporate the use of State Management implementation, such as NGXS. NGXS is a state management pattern + library for Angular . It acts as a single  source of truth for your application's state, providing simple rules for  predictable  state mutations - NGXS documentation.   Here is the example of sending a GET request through a service call.   ngOnInit(): void {     this.spinnerLoading = true;     this.dataSource$ = this.postListService.getPosts();     this.getPostsData();     this.spinnerLoading = false;    }   getPostsData() {     this.dataSource$.subscribe(        ( res )...

Using GitHub REST API to display your repositories with Angular

This post covers the authentication to GitHub REST API with fine-grained personal access token, sending the request to GitHub server with Octokit library, and displaying the list of your repositories in Angular component. Instructions on how to create the token can be found in GitHub documentation and will not be covered in this post.  Photo by Douglas Lopes on Unsplash    Handling your token in Angular app Before moving any application or a page that uses sensitive information such as passwords or tokens into a production, you need to be aware that sensitive data cannot be hidden from a client (user) if it is stored in the application. The best way for production use is to serve the token from a back-end or a proxy server. There are plenty of examples on how to do that, for now we will store the token in the app, so that we can focus on authentication and pulling the data from the GitHub server. Store the token in a config file Once you have created your G...