<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Khaja Moizuddin</title>
    <description>The latest articles on DEV Community by Khaja Moizuddin (@khajamoizuddin).</description>
    <link>https://dev.to/khajamoizuddin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F308673%2F9b00fb43-82b3-4d0e-884a-2708bde28f2c.jpg</url>
      <title>DEV Community: Khaja Moizuddin</title>
      <link>https://dev.to/khajamoizuddin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khajamoizuddin"/>
    <language>en</language>
    <item>
      <title>Angular's Data Binding from Scratch - Part One.</title>
      <dc:creator>Khaja Moizuddin</dc:creator>
      <pubDate>Tue, 14 Jan 2020 20:49:16 +0000</pubDate>
      <link>https://dev.to/khajamoizuddin/angular-s-data-binding-from-scratch-part-one-2bm6</link>
      <guid>https://dev.to/khajamoizuddin/angular-s-data-binding-from-scratch-part-one-2bm6</guid>
      <description>&lt;p&gt;Introduction&lt;/p&gt;

&lt;p&gt;In this article, we will learn about Data Binding in Angular. As we know Data Binding is used for binding the data from View to Component or Component to View. In Angular, we have two different types of Data Binding for binding the data from Component.ts class file to Component.html or Component.html to Component.ts or Vice versa.&lt;/p&gt;

&lt;p&gt;One way Data Binding&lt;/p&gt;

&lt;p&gt;In one-way data binding, we have two different types of data binding that are binding of data from Component.html or View to Component.ts class file or Component.ts class file to Component.html.&lt;/p&gt;

&lt;p&gt;We have different ways of binding the data from Component.ts class file to Component.html as shown below.&lt;br&gt;
String Interpolation&lt;br&gt;
Property Binding&lt;br&gt;
Style Binding&lt;br&gt;
Class Binding&lt;br&gt;
Attribute Binding etc.&lt;br&gt;
In order to pass the data from Component.html (View) to Component.ts or One-way data binding, we use Event Binding.&lt;/p&gt;

&lt;p&gt;Another way to bind the data from Component.html or View to Component.ts or Component.ts to Component.html we use&lt;/p&gt;

&lt;p&gt;Two-way Data Binding.&lt;/p&gt;

&lt;p&gt;String Interpolation&lt;/p&gt;

&lt;p&gt;In String Interpolation we bind the data from Component.ts class file to Component.html by using the expression in double curly braces. If we don't pass the data or the component's field in double curly braces then angular treat this as a string value and display the string value to the end-user.&lt;/p&gt;

&lt;p&gt;For example,&lt;/p&gt;

&lt;p&gt;Open the Component.ts file and place the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class Test3Component implements OnInit {    
   firstName: string = 'Khaja';    
   lastName: string = 'Moizuddin';    
   number1: number = 100;    
   number2: number = 200;    
   totalAmount: number = this.number1 + this.number2;    
   fullName: string = this.firstName + this.lastName;    
   fullNameVal:string;    
   totalVal:number;    
   csharpCornerURL: string = 'https://www.c-sharpcorner.com/members/khaja-moiz';    
   myImagePath: string = 'assets/Images/mvp1.jpg';    
   heightImg: number = 50;    
   widthImg:number = 50;    
   onButtonClick: string;    
   onDoubleClick: string;    

  getTotalAmount1() {    
    return this.number1 + this.number2;    
 }    

  getTotalAmount2() {    
return this.totalVal = this.number1 + this.number2;    

  }    

  getTotalAmount3() {    
   return this.totalVal = this.totalAmount;    
  }    
  getFullName1() {    
    return this.firstName + this.lastName;    
  }    
  getFullName2() {    
 return this.fullNameVal = this.firstName + this.lastName;    
  }    
  getFullName3() {    
    return this.fullNameVal = this.fullName;    
  }    
  onBtnClick() {    
return this.onButtonClick = 'Welcome ' + this.firstName;    
  }    
  onDblClick(){    
    return this.onDoubleClick = 'Welcome ' + this.lastName;    
  }    
constructor() { }    
  ngOnInit() {    
  }    
}    

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now open the Component.html file and place the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h2&amp;gt;STRING INTERPOLATION&amp;lt;/h2&amp;gt;    
&amp;lt;hr&amp;gt;    
&amp;lt;h3&amp;gt; firstName is:{{this.firstName}}  &amp;lt;/h3&amp;gt;    
&amp;lt;h3&amp;gt; lastName is: {{this.lastName}} &amp;lt;/h3&amp;gt;    
&amp;lt;h3&amp;gt; fullName is:{{this.fullName}}  &amp;lt;/h3&amp;gt;    
&amp;lt;h3&amp;gt; fullName1 is:{{this.getFullName1()}}  &amp;lt;/h3&amp;gt;    
&amp;lt;h3&amp;gt; fullName2 is:{{this.getFullName2()}} &amp;lt;/h3&amp;gt;    
&amp;lt;h3&amp;gt; fullName3 is:{{this.getFullName3()}}  &amp;lt;/h3&amp;gt;    
&amp;lt;h3&amp;gt; Number1 is : {{this.number1}} &amp;lt;/h3&amp;gt;    
&amp;lt;h3&amp;gt; Number2 is:{{this.number2}}  &amp;lt;/h3&amp;gt;    
&amp;lt;h3&amp;gt; TotalAmount is:{{this.totalAmount}}  &amp;lt;/h3&amp;gt;    
&amp;lt;h3&amp;gt; TotalAmount1 is:{{this.getTotalAmount1()}}  &amp;lt;/h3&amp;gt;    
&amp;lt;h3&amp;gt; TotalAmount2 is:{{this.getTotalAmount2()}}  &amp;lt;/h3&amp;gt;    
&amp;lt;h3&amp;gt;TotalAmount3 is: {{this.getTotalAmount3()}}  &amp;lt;/h3&amp;gt;   

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here in the above code we used different ways of binding the data in String Interpolation, we used double curly braces for binding the data from component.ts to component.html with this it converts the field values as expression.&lt;/p&gt;

&lt;p&gt;In the above we used fullName: string = this.firstName + this.lastName; or totalAmount: number = this.number1 + this.number2; which converts the values as an expressions and returns the result to the end user.&lt;/p&gt;

&lt;p&gt;Property Binding &lt;/p&gt;

&lt;p&gt;In Property binding, we bind the data from Component.ts to Component.html. The HTML elements property is bound with the values from Component.ts file using square brackets [].&lt;/p&gt;

&lt;p&gt;For Example,&lt;/p&gt;

&lt;p&gt;Now open the Component.html file and place the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span [innerText]='this.firstName'&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;span [innerHTML] = 'this.lastName'&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;span innerText = '{{this.firstName}}'&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;span innerHTML = '{{this.lastName}}'&amp;gt;&amp;lt;/span&amp;gt;    

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the above code we used [innerHTML] and [innerText] which is nothing but property binding, here the values this.firstName, this.lastName is binded from the Component.ts file, the Output will be visible to the end user which will be placed in between the span tags.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!--BINDING PROPERTY TO DOM ELEMENT--&amp;gt;    
&amp;lt;span [attr.innerText]='this.firstName'&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;span [attr.innerHTML] = 'this.lastName'&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;span attr.innerText = '{{this.firstName}}'&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;span attr.innerHTML = '{{this.lastName}}'&amp;gt;&amp;lt;/span&amp;gt; 

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With the above code, we used attr attribute which is nothing but attribute binding with property name which binds the Component's value to the DOM element. The output will not be visible to the end-user but the innerText and innerHTML property will be added to the span tags which can be shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;a href="{{this.csharpCornerURL}}" target="_blank"&amp;gt;CsharpCorner&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;a [href]='this.csharpCornerURL' target="_blank"&amp;gt;CsharpCorner&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;a attr.href = '{{this.csharpCornerURL}}' target="_blank"&amp;gt;CsharpCorner&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;a [attr.href]='this.csharpCornerURL' target="_blank"&amp;gt;CsharpCorner&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;    

&amp;lt;img src='{{this.myImagePath}}' height='{{this.heightImg}}' width="{{this.widthImg}}" /&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;img [src]='this.myImagePath' [height]='this.heightImg' [width]="this.widthImg"&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;img attr.src = '{{this.myImagePath}}' attr.height='{{this.heightImg}}' attr.width="{{this.widthImg}}"&amp;gt;&amp;lt;br&amp;gt;    
&amp;lt;img [attr.src]='this.myImagePath' [attr.height]='this.heightImg' [attr.width]="this.widthImg"&amp;gt;  

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here i have used different ways of binding the Component's value to the property href and src as shown in the above code.&lt;/p&gt;

&lt;p&gt;We will see other data binding properties in my next article.&lt;/p&gt;

&lt;p&gt;Thanks &amp;amp; I hope this helps you.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Consuming RestApi using HttpClient</title>
      <dc:creator>Khaja Moizuddin</dc:creator>
      <pubDate>Sun, 12 Jan 2020 10:45:43 +0000</pubDate>
      <link>https://dev.to/khajamoizuddin/consuming-restapi-using-httpclient-2o8j</link>
      <guid>https://dev.to/khajamoizuddin/consuming-restapi-using-httpclient-2o8j</guid>
      <description>&lt;p&gt;Introduction&lt;/p&gt;

&lt;p&gt;In this article, we will learn how to Consume RestAPI services using HttpClient. It is used for the Authentication and Authorization of users with LDAP Active Directory.&lt;br&gt;
In C# we can consume RestAPI using the following ways,&lt;br&gt;
HttpWebRequest or HttpWebResponse&lt;br&gt;
WebClient&lt;br&gt;
HttpClient&lt;br&gt;
RestSharp Classes etc.&lt;br&gt;
The best and most straightforward way to consume RestAPI is by using the HttpClient class.&lt;/p&gt;

&lt;p&gt;In order to Consume RestAPI using HttpClient, we can use various methods like&lt;br&gt;
ReadAsAsync&lt;br&gt;
PostAsync&lt;br&gt;
PutAsync&lt;br&gt;
GetAsync&lt;br&gt;
SendAsync etc. &lt;br&gt;
In this article, I used HttpClient to Consume RestAPI Services. In order to Consume Restful Services, first of all, we need to generate access token by providing the accessToken URL with a POST request as well as the headers such as apikey, Authorization &amp;amp; Content-Type. Here apikey, ClientID, and Client Secure which will be provided by the service provider, Authorization contains Client ID and Client Secure which can be encoded with Base64String and passed as encrypted value with Basic as prefix and Content-Type should be "application/x-www-form-urlencoded".&lt;/p&gt;

&lt;p&gt;For example: Authorization = Basic AccessToken&lt;/p&gt;

&lt;p&gt;In the body, we need to provide grant_type as client_credentials and scope as public with "x-www-form-urlencoded" value.&lt;/p&gt;

&lt;p&gt;When we execute the POST request by providing all the required details as mentioned above, the access token will be generated.&lt;/p&gt;

&lt;p&gt;We can use POSTMAN tool to test or generate the access token.&lt;/p&gt;

&lt;p&gt;In this article, I am going to use two different methods as shown below.&lt;br&gt;
EmployeeRegisteration&lt;br&gt;
EmployeeSearch etc. &lt;/p&gt;

&lt;p&gt;In order to work with the above methods, each method contains URL endpoint with either GET/PUT/POST/DELETE requests, etc. From the above methods, we have two POST request and two GET requests, i.e. EmployeeRegisteration &amp;amp; EmployeeSearch are POST request and GetSecretQuestions &amp;amp; GetCountryNames are GET requests.&lt;br&gt;
EmployeeRegisteration method contains headers like Content-type as application/json, apikey, and Authorization.&lt;/p&gt;

&lt;p&gt;Here Authorization contains the generated token with Bearer as the prefix.&lt;/p&gt;

&lt;p&gt;For Example Authorization = Bearer AccessToken&lt;/p&gt;

&lt;p&gt;And we need to pass the Body with the JSON Data as raw.&lt;/p&gt;

&lt;p&gt;When executed the EmployeeRegisteration method with POST request by providing all the required details or parameters we get the JSON response with 200 OK which means its successful. If it is unsuccessful then we will get different messages like 500 Internal Server Error or 400 Bad Request etc. If it is successful then we will get a JSON response with the complete information.&lt;/p&gt;

&lt;p&gt;For remaining methods like EmployeeSearch, GetSecretQuestions, GetCountryNames, the headers will be the same only the Body with JSON Data changes according to the requirement.&lt;/p&gt;

&lt;p&gt;Below is the code to understand the Consumption of RestAPI using HttpClient.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;GenerateAccessToken&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Below is the code for the GenerateAccessToken Method.   &lt;/p&gt;

&lt;pre&gt;
class Program  
    {  
        string clientId = "a1s2d3f4g4h5j6k7l8m9n1b2v3c4";  
        string clientSecret = "z1x2c3v4b4n5m6l1k2j3h4g5f6d7s8";  
        string apikey = "o1i2u3y4t5r6e7w8q9a1s2d3f4g5h6j6k7l8";  
        string createNewUserJson;  
        string searchUserJson;  
        string accessToken;  
        EmployeeRegisterationResponse registerUserResponse = null;  
        EmployeeSearchResponse empSearchResponse = null;  
        GetSecurityQuestionsResponse getSecurityQueResponse = null;  
        GetCountryNamesResponse getCountryResponse = null;   
static void Main(string[] args)  
        {  
            Program prm = new Program();  
            prm.InvokeMethod();  
              
         }  
public async void InvokeMethod()  
        {  
            Task getAccessToken = GenerateAccessToken();  
            accessToken = await getAccessToken;  
  
            Task registerResponse = EmployeeRegistration(accessToken);  
            registerUserResponse = await registerResponse;  
  
            Task employeeSearchResponse = EmployeeSearch(accessToken);  
            empSearchResponse = await employeeSearchResponse;  
  
            Task getSecurityResponse = GetSecretQuestions(accessToken);  
            getSecurityQueResponse = await getSecurityResponse;  
  
            Task getCountryNamesResponse = GetCountryNames(accessToken);  
            getCountryResponse = await getCountryNamesResponse;  
        }  
public async Task GenerateAccessToken()  
        {  
            AccessTokenResponse token = null;  
  
            try  
            {  
                HttpClient client = HeadersForAccessTokenGenerate();  
                string body = "grant_type=client_credentials&amp;amp;scope=public";  
                client.BaseAddress = new Uri(accessTokenURL);  
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, client.BaseAddress);  
                request.Content = new StringContent(body,  
                                                    Encoding.UTF8,  
                                                    "application/x-www-form-urlencoded");//CONTENT-TYPE header  
  
                List&amp;gt; postData = new List&amp;gt;();  
  
                postData.Add(new KeyValuePair("grant_type", "client_credentials"));  
                postData.Add(new KeyValuePair("scope", "public"));  
  
                request.Content = new FormUrlEncodedContent(postData);  
HttpResponseMessage tokenResponse = client.PostAsync(baseUrl, new FormUrlEncodedContent(postData)).Result;  
  
                //var token = tokenResponse.Content.ReadAsStringAsync().Result;    
                token = await tokenResponse.Content.ReadAsAsync(new[] { new JsonMediaTypeFormatter() });  
            }  
  
  
            catch (HttpRequestException ex)  
            {  
                throw ex;  
            }  
            return token != null ? token.AccessToken : null;  
  
        }  
private HttpClient HeadersForAccessTokenGenerate()  
        {  
            HttpClientHandler handler = new HttpClientHandler() { UseDefaultCredentials = false };  
            HttpClient client = new HttpClient(handler);  
            try  
            {  
                client.BaseAddress = new Uri(baseUrl);  
                client.DefaultRequestHeaders.Accept.Clear();  
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));  
                client.DefaultRequestHeaders.Add("apikey", apikey);  
                client.DefaultRequestHeaders.Add("Authorization", "Basic " + Convert.ToBase64String(  
                         System.Text.ASCIIEncoding.ASCII.GetBytes(  
                            $"{clientId}:{clientSecret}")));  
            }  
            catch (Exception ex)  
            {  
                throw ex;  
            }  
            return client;  
        } 
 &lt;/pre&gt;


&lt;b&gt;EmployeeRegistration&lt;/b&gt; 

 
Below is the code for EmployeeRegistration Method. 

&lt;pre&gt;
public async Task EmployeeRegistration(string accessToken)  
        {  
            EmployeeRegisterationResponse employeeRegisterationResponse = null;  
            try  
            {  
                string createEndPointURL = "https://www.c-sharpcorner/registerUsers";  
                string username = "KhajaMoiz", password = "Password", firstname = "Khaja", lastname = "Moizuddin", email = "Khaja.Moizuddin@gmail.com";  
                HttpClient client = Method_Headers(accessToken, createEndPointURL);  
                string registerUserJson = RegisterUserJson(username, password, firstname, lastname, email);  
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, Uri.EscapeUriString(client.BaseAddress.ToString()));  
                request.Content = new StringContent(registerUserJson, Encoding.UTF8, "application/json");  
                request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");  
                HttpResponseMessage tokenResponse = client.PostAsync(Uri.EscapeUriString(client.BaseAddress.ToString()), request.Content).Result;  
                if (tokenResponse.IsSuccessStatusCode)  
                {  
                    employeeRegisterationResponse = await tokenResponse.Content.ReadAsAsync(new[] { new JsonMediaTypeFormatter() });  
                }  
            }  
            catch (HttpRequestException ex)  
            {  
  
            }  
            return employeeRegisterationResponse;  
        }  
private HttpClient Method_Headers(string accessToken, string endpointURL)  
       {  
           HttpClientHandler handler = new HttpClientHandler() { UseDefaultCredentials = false };  
           HttpClient client = new HttpClient(handler);  
  
           try  
           {  
               client.BaseAddress = new Uri(endpointURL);  
               client.DefaultRequestHeaders.Accept.Clear();  
               client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));  
               client.DefaultRequestHeaders.Add("apikey", apikey);  
               client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);  
           }  
           catch (Exception ex)  
           {  
               throw ex;  
           }  
           return client;  
       }  
private string RegisterUserJson(string userName, string password, string firstName, string lastName, string emailAddress)  
       {  
           registerUserJSON =  
               "{"  
                      + "\"RegisterUserInfo\": {"  
                      + "\"username\": \"" + userName + "\","  
                      + "\"password\": \"" + password + "\","  
                      + "\"firstName\": \"" + firstName + "\","  
                      + "\"lastName\": \"" + lastName + "\","  
                      + "\"emailAddress\": \"" + emailAddress + "\","  
               + "},"  
       }";  
  
           return registerUserJSON;  
       }  
&lt;/pre&gt;

&lt;p&gt;Thanks &amp;amp; I hope this helps you.&lt;/p&gt;

</description>
      <category>restapi</category>
      <category>consumerestapihttpclient</category>
      <category>httpclient</category>
    </item>
  </channel>
</rss>
