Create Custom / User Defined Web API GET Method And Test In Talend API

 You will learn two major things in this article:
  • Create GET Custom Method Web API  using .Net Framework.
  • Testing Web API GET Method using Talend Chrome Browser Extension.
We are going acheive the above two major things with the help of the followings steps,
  • Create SQL Table and Insert Data using Query
  • Asp.Net Web API Application Creation
  • Linq to Sql Class
  • Write GET Custom Method of Web API
  • Test Asp.Net Web API GET Method in Browser
  • Install Talend Extension in Chrome Browser
  • Test Asp.Net Web API GET Method for XML and JSON output.

Create SQL Table and Insert Data using Query

 
Connect to your SQL Server,
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Table Creation SQL Script,
  1. USE [MbkTest]   
  2. go   
  3. /****** Object: Table [dbo].[tblFriends] Script Date: 07-Jan-20 12:53:31 PM ******/   
  4. SET ansi_nulls ON   
  5. go   
  6. SET quoted_identifier ON   
  7. go   
  8. SET ansi_padding ON   
  9. go   
  10. CREATE TABLE [dbo].[tblfriends]   
  11.   (   
  12.      [friendid]       [INT] IDENTITY(1, 1) NOT NULL,   
  13.      [friendname]     [VARCHAR](100) NULL,   
  14.      [phonenumber]    [VARCHAR](50) NULL,   
  15.      [emailid]        [VARCHAR](100) NULL,   
  16.      [country]        [VARCHAR](100) NULL,   
  17.      [dob]            [DATETIME] NULL,   
  18.      [ismarried]      [BITNULL,   
  19.      [salaryperannum] [NUMERIC](10) NULL,   
  20.      PRIMARY KEY CLUSTERED ( [friendid] ASC )WITH (pad_index = OFF,   
  21.      statistics_norecompute = OFF, ignore_dup_key = OFF, allow_row_locks = on,   
  22.      allow_page_locks = onON [PRIMARY]   
  23.   )   
  24. ON [PRIMARY]   
  25. go   
  26. SET ansi_padding OFF   
  27. go   
Insert Table Data Using SQL Script,
  1. insert into tblFriends values ('Suresh Vyas','98612134512','sureshvyas@zohax.com','India',1990/01/01,1,450000)    
  2. insert into tblFriends values ('Manoj Kalla','9869166077','manojkalla@hotmail.com','India',1980/02/05,1,950000)    
  3. insert into tblFriends values ('Kamlesh Goenka','981916607','kamleshgoenka@hotail.com','India',1970/02/06,1,750000)    
  4. insert into tblFriends values ('Prashant Bansal','781214607','prashantbansal@soril.com','US',1989/01/04,01,250000)    
  5. insert into tblFriends values ('Nitin Tiwari','811012607','nitin@indl.com','US',1992/01/04,0,350000)    
  6. insert into tblFriends values ('Mahesh Jadhav','921052607','mahesh@utsavl.com','US',1998/01/06,0,42000)    
Select Query to Check the Records,
  1. select * from [dbo].[tblFriends]  
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Create ASP.NET Web Application project called “LearnWebApi”
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
You can check in the above screen shot that the MVC and Web API checkboxes are selected by default.
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Project is created successfully.
 

Connecting to MBKTEST database

 
For Server Explorer click on VIEW --->Server Explorer
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Create Custom / User Defined Web API GET Method And Test In Talend API 
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Now insert LINQ TO SQL,
 
Right click on Project Select ADD--> NEW ITEM
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Select Data then select “LINQ TO SQL CLASSES”.
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Drag tblFriends table on (MbkTestDataClasses.dbml) Linq To SQL class.
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Switch to default controller that is ValuesController (ValueController.cs file) which is located inside root’s Controller folder.
 
Code
  1. [HttpGet]      
  2. [Route("api/FriendListMsg")]    
  3. public HttpResponseMessage GetFriendList()    
  4. {    
  5.    MbkTestDataClassesDataContext db = new MbkTestDataClassesDataContext();    
  6.    var FriendList = (from a in db.tblFriends select a).ToList();    
  7.    return Request.CreateResponse(HttpStatusCode.OK, FriendList);    
  8. }    
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Press F5 and Check on browser.
 
Just type ADDRESS
 
http://localhost:50297/api/FriendListMsg
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 

How to install Talend API Tester?

 
Open Chorme browser, click on the top left side and there is a button called APPS
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Or
 
Type on Address Bar:chrome://apps/
 
Select WEB STORE
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Search Text Box type ---> “Talend API Tester”
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
After extension installation
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Now run the Talend API Tester by clicking on the right top side.
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Sending application/xml request to server to get output in XML format.
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
XML OUTPUT RECEIVED FROM SERVER,
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Sending application/json request to server to get output in JSON format.
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
JSON OUTPUT RECEIVED FROM SERVER,
 
Create Custom / User Defined Web API GET Method And Test In Talend API
 
Happy Coding. . . !