Yes there is Microsoft.SharePoint API used, using below c# code you can connect to SharePoint root site:
SPContext.Current.Site.URL
For subsites you can use the below code:
SPContext.Current.Web.URL
For ClientContext use the below code:
ClientContext context = new ClientContext("https://mycompany.sharepoint.com/sites/parts/");
WindowsImpersonationContext ctx = null;
if (!WindowsIdentity.GetCurrent().IsSystem)
{
ctx = WindowsIdentity.Impersonate(System.IntPtr.Zero);
// The SharePoint web at the URL.
Web web = context.Web;
// We want to retrieve the web's properties.
context.Load(web);
// Execute the query to the server.
context.ExecuteQuery();
// Now, the web's properties are available and we could display
// web properties, such as title.
System.Console.WriteLine("Web Title");
System.Console.WriteLine(web.Title);
}