Netstair RESTFul API Test

Single Visual Studio DOT.NET 4.5.2 RESTFul WEB API

HOW TO Consume the Zip Codes, Area Codes API (Application Interface)

Create a Visual Studio Project using Framework 4.5 or higher and copy the Webform and code behind below.

default.aspx
<%@ Page Title="API-Test" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="NetstairAPIWEB._Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

    <div class="jumbotron">
        <h1>Netstair API</h1>
        <p class="lead">ASP.NET RestFul API - Fetch by Zipcode and Area code</p>
        <p><a href="http://www.netstair.com" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
        <p><asp:ValidationSummary ID="ValSum1" ShowSummary="true" ValidationGroup="fldValGrp1" runat="server" /></p>
        <p><asp:ValidationSummary ID="ValSum2" ShowSummary="true" ValidationGroup="fldValGrp1" runat="server" /></p>
    </div>

    <div class="row">
        <div class="col-md-4">
            <h2>Zip code</h2>
            <p>                
                
                <asp:TextBox ID="txtZip" runat="server"></asp:TextBox>                
                <asp:Button ID="btnSubmit" Text="Fetch Zip Code" OnClick="btnFetchZipcodes_Click" ValidationGroup="fldValGrp1" runat="server" />                    
            </p>
            <p><asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtZip" ValidationGroup="fldValGrp1" runat="server" ForeColor="Red" SetFocusOnError="true" ErrorMessage="A Valid Zip code is required!"></asp:RequiredFieldValidator></p>
        </div>
        <div class="col-md-4">
            <h2>Area Code</h2>
            <p>               
                
                <asp:TextBox ID="txtAreaCode" runat="server"></asp:TextBox>                
                <asp:Button ID="Button1" Text="Fetch Area Code" OnClick="btnFetchAreaCode_Click" ValidationGroup="fldValGrp2" runat="server" />                   
             </p>            
            <p><asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtAreaCode" ValidationGroup="fldValGrp2" runat="server" ForeColor="Red" SetFocusOnError="true" ErrorMessage="A Valid Area code is required!"></asp:RequiredFieldValidator></p>
        </div>   

    </div>
    <p><asp:Literal ID="litContent" runat="server"></asp:Literal></p>

</asp:Content>
default.aspx.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetstairWebAPI;    //- You need to download this .DLL

namespace NetstairAPIWEB
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnFetchAreaCode_Click(object sender, EventArgs e)
        {
            var ACodeId = txtAreaCode.Text.Trim();
            var JSON_RESULT_STRING = "Invalid Area code entered.";
            try
            {
                NetstairAPIAreaCode oAce = new NetstairAPIAreaCode(ACodeId);
            JSON_RESULT_STRING = "<b>Your Areacode fetched RestSharp result:</b><br/>" + oAce.Reponse_Value;
            JSON_RESULT_STRING += "<br/><p><b>Your Zipcode fetched Parsed JSON result:</b></p>";
            JSON_RESULT_STRING += "<p>Area code: " + oAce.Areacode + "</p>";
            JSON_RESULT_STRING += "<p>Country: " + oAce.Country + "</p>";
            JSON_RESULT_STRING += "<p>City: " + oAce.City + "</p>";
            JSON_RESULT_STRING += "<p>State: " + oAce.State + "</p>";
            JSON_RESULT_STRING += "<p>Latitude: " + oAce.Latitude + "</p>";
            JSON_RESULT_STRING += "<p>Longitude: " + oAce.Longitude + "</p>";
            }
            catch (Exception em1)
            {
                Console.WriteLine(em1.Message.ToString());
                txtAreaCode.Text = "";
            }            
            //- Display
            this.litContent.Text = JSON_RESULT_STRING;            
        }
        protected void btnFetchZipcodes_Click(object sender, EventArgs e)
        {
            var zipId = txtZip.Text.Trim();
            var JSON_RESULT_STRING = "Invalid Zip code entered.";
            try
            {
                NetstairAPIZip oZip = new NetstairAPIZip(zipId);
                JSON_RESULT_STRING = "<b>Your Zipcode fetched RestSharp result:</b><br/>" + oZip.Reponse_Value;
                JSON_RESULT_STRING += "<br/><p><b>Your Zipcode fetched Parsed JSON result:</b></p>";
                JSON_RESULT_STRING += "<p>Zip code: " + oZip.Zipcode + "</p>";
                JSON_RESULT_STRING += "<p>County: " + oZip.County + "</p>";
                JSON_RESULT_STRING += "<p>City: " + oZip.City + "</p>";
                JSON_RESULT_STRING += "<p>State: " + oZip.State + "</p>";
                JSON_RESULT_STRING += "<p>Latitude: " + oZip.Latitude + "</p>";
                JSON_RESULT_STRING += "<p>Longitude: " + oZip.Longitude + "</p>";
            }
            catch (Exception em2)
            {
                Console.WriteLine(em2.Message.ToString());
                txtZip.Text = "";
            }
            //- Display
            this.litContent.Text = JSON_RESULT_STRING;            
        }
    }
}
Download API Access .DLL Here -->WebApiAccessClient.zip

Add Feedback