Files
PostManCloneApp/PostmanCloneUI/Dashboard.cs
2024-06-05 11:34:55 +02:00

48 lines
1.2 KiB
C#

using PostmanCloneLibrary;
namespace PostmanCloneUI;
public partial class Dashboard : Form
{
private readonly ApiAccess _apiAccess = new();
public Dashboard()
{
InitializeComponent();
httpVerbSelection.SelectedItem = "GET";
}
private async void callApi_Click(object sender, EventArgs e)
{
systemStatus.Text = "Calling API...";
resultsText.Text = "";
// Validate the API URL
if (_apiAccess.IsValidUrl(apiText.Text) == false)
{
systemStatus.Text = "Invalid URL...";
return;
}
HttpAction action;
if (Enum.TryParse(httpVerbSelection.SelectedItem!.ToString(), out action) == false)
{
systemStatus.Text = "Invalid Http Verb";
return;
}
try
{
resultsText.Text = await _apiAccess.CallApiAsync(apiText.Text, bodyText.Text, action);
callData.SelectedTab = resultsTab;
resultsTab.Focus();
systemStatus.Text = "Ready";
}
catch (Exception ex)
{
resultsText.Text = "Error: " + ex.Message;
systemStatus.Text = "Error";
}
}
}