This project is a lightweight .NET 8 Web API that converts HTML content into structured JSON. It uses HtmlAgilityPack to parse HTML and allows XPath filtering to extract specific parts of HTML. The API is designed with clean separation between models, settings, and service logic, which is ideal for microservice-based architectures.
- ✅ Converts raw HTML into structured JSON
- 🔎 Supports optional XPath filtering to select specific HTML nodes
- 🌐 Web API powered by ASP.NET Core (.NET 8)
- ⚙️ Configurable base URL, endpoint, and XPath via dependency injection
- 💡 Simple, testable, and clean architecture
- 🧩 Uses
HttpClientFactoryfor efficient and reusable HTTP requests
Adapter\_HTML/
├── TagModel.cs // Model for HTML elements and attributes
├── AttributeModel.cs // Sub-model for HTML attributes
├── HtmlAdapterSettings.cs // Config: base URL, endpoint, XPath, etc.
├── HtmlToJsonConverter.cs // Core logic: fetch, parse, and convert HTML
├── Program.cs // Web API entry point and service configuration
- Open the .sln file in Visual Studio 2022.
- Ensure that Adapter_HTML is set as the startup project.
- Press F5 or click the Start button (
▶️ ) to run the application. - Once the application is running, the Swagger UI will open automatically at: https://localhost:{PORT}/swagger (replace {PORT} with your actual port number).
- In Swagger UI, locate the /convert endpoint under the appropriate controller.
- Click Try it out, then Execute to send a request. The API will respond with JSON data based on the XPath and other settings defined in your appsettings.json.
{
"HtmlAdapter": {
"BaseUrl": "http://www.koeri.boun.edu.tr",
"Endpoint": "/scripts/sondepremler.asp",
"XPath": "//a"
}
}[
"tagName": "a",
"innerText": "",
"attributes": [
{
"name": "title",
"value": "B�LGESEL DEPREM-TSUNAM� �ZLEME VE DE�ERLEND�RME MERKEZ�"
},
{
"name": "href",
"value": "http://udim.koeri.boun.edu.tr"
},
{
"name": "target",
"value": "_blank"
}
]
]- .NET 8 SDK
- HtmlAgilityPack
- ASP.NET Core Web API
I have also tested the API endpoints using Postman to verify that the JSON responses are returned correctly and formatted as expected.


