Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: CI

on:
push:
branches: ['**']
pull_request:
branches: [main]

env:
DOTNET_VERSION: '10.x'

jobs:
build-and-test:
name: Build & Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Restore
run: dotnet restore src/HttpClientServiceHelper.sln

- name: Build
run: dotnet build src/HttpClientServiceHelper.sln --no-restore --configuration Release

- name: Test
run: >-
dotnet test src/HttpClientServiceHelper.Tests/HttpClientServiceHelper.Tests.csproj
--no-build --configuration Release
--logger trx
--results-directory ${{ github.workspace }}/TestResults
/p:CollectCoverage=true
/p:CoverletOutputFormat=cobertura
"/p:CoverletOutput=${{ github.workspace }}/TestResults/coverage.cobertura.xml"

- name: Install report generator
run: dotnet tool install --global dotnet-reportgenerator-globaltool

- name: Generate coverage report
run: >-
reportgenerator
"-reports:${{ github.workspace }}/TestResults/coverage.cobertura.xml"
"-targetDir:${{ github.workspace }}/TestResults/CoverageReport"
-reportTypes:htmlInline

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.os }}
path: ${{ github.workspace }}/TestResults/*.trx

- name: Upload coverage report
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-report-${{ matrix.os }}
path: ${{ github.workspace }}/TestResults/CoverageReport

publish:
name: Publish to NuGet
runs-on: ubuntu-latest
needs: build-and-test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Restore
run: dotnet restore src/HttpClientServiceHelper.sln

- name: Pack
run: dotnet pack src/HttpClientServiceHelper/HttpClientServiceHelper.csproj --configuration Release

- name: Push to NuGet
run: >-
dotnet nuget push "**/*.nupkg"
--source https://api.nuget.org/v3/index.json
--api-key ${{ secrets.NUGET_API_KEY }}
--skip-duplicate
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# HttpClientServiceHelper

.NET HTTP Client Service library.

## Stats and Reports

![GitHub contributors](https://img.shields.io/github/contributors-anon/daraoladapo/HttpClientServiceHelper)
[![Build Status](https://dev.azure.com/daraoladapo/HttpClientServiceHelper/_apis/build/status/HttpClientServiceHelper?branchName=master)](https://dev.azure.com/daraoladapo/HttpClientServiceHelper/_build/latest?definitionId=3&branchName=master)
[![Build Status](https://github.com/DaraOladapo/HttpClientServiceHelper/actions/workflows/ci.yml/badge.svg)](https://github.com/DaraOladapo/HttpClientServiceHelper/actions/workflows/ci.yml)
![Nuget](https://img.shields.io/nuget/dt/HttpClientServiceHelper?label=Total%20NUGET%20Downloads)
![GitHub](https://img.shields.io/github/license/daraoladapo/httpclientservicehelper)



![GitHub](https://img.shields.io/github/license/daraoladapo/httpclientservicehelper)

Use this library to quickly bootstrap your HttpClient Service calls.
It uses the System.Net.Http library.
Expand All @@ -34,4 +32,4 @@ Copy the following into the .csproj file of your project (using version 1.0.0 as

Get the NUGET Package [here](https://www.nuget.org/packages/HttpClientServiceHelper).

Happy Usage!
Happy Usage!
120 changes: 0 additions & 120 deletions azure-pipelines.yml

This file was deleted.

26 changes: 26 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# API Reference

## Get
Handles HTTP GET requests. See `src/HttpClientServiceHelper/Get.cs` for implementation details.

## Post
Handles HTTP POST requests. See `src/HttpClientServiceHelper/Post.cs` for implementation details.

## Put
Handles HTTP PUT requests. See `src/HttpClientServiceHelper/Put.cs` for implementation details.

## Patch
Handles HTTP PATCH requests. See `src/HttpClientServiceHelper/Patch.cs` for implementation details.

## Delete
Handles HTTP DELETE requests. See `src/HttpClientServiceHelper/Delete.cs` for implementation details.

## HttpClientServiceHelper
Central helper class for HTTP operations. See `src/HttpClientServiceHelper/HttpClientServiceHelper.cs`.

## Models
- **Authorization**: Represents authorization data (e.g., Bearer tokens).
- **Header**: Represents custom HTTP headers.
- **GenericModel**: Generic model for request/response payloads.

See `src/HttpClientServiceHelper/Models/` for all model classes.
45 changes: 45 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# HttpClientServiceHelper Documentation

## Overview
HttpClientServiceHelper is a .NET library designed to simplify HTTP operations (GET, POST, PUT, PATCH, DELETE) with a focus on reusability, testability, and ease of use. It provides helper classes and models to streamline HTTP requests and responses, including support for custom headers and authorization.

## Project Structure
- **src/HttpClientServiceHelper/**: Main library source code
- **src/HttpClientServiceHelper.Tests/**: Unit tests for the library
- **src/HttpClientServiceHelper/Models/**: Data models for headers, authorization, and generic payloads
- **src/HttpClientServiceHelper/Assets/**: Static assets (if any)
- **/docs/**: Project documentation

## Main Components
### Core Classes
- **Get.cs**: Handles HTTP GET requests
- **Post.cs**: Handles HTTP POST requests
- **Put.cs**: Handles HTTP PUT requests
- **Patch.cs**: Handles HTTP PATCH requests
- **Delete.cs**: Handles HTTP DELETE requests
- **HttpClientServiceHelper.cs**: Central helper class for HTTP operations

### Models
- **Authorization.cs**: Represents authorization data (e.g., Bearer tokens)
- **Header.cs**: Represents custom HTTP headers
- **GenericModel.cs**: Generic model for request/response payloads

## Usage
1. Add the library to your .NET project.
2. Instantiate the relevant helper class (e.g., `Get`, `Post`).
3. Use the provided methods to perform HTTP operations, passing in models as needed.

## Testing
- Unit tests are located in `src/HttpClientServiceHelper.Tests/`.
- Tests cover all HTTP methods and edge cases.

## Upgrading
- The project targets the latest .NET (net10.0) for the main library and will be updated for the test project.
- Dependencies are kept up to date (e.g., Newtonsoft.Json 13.0.3).

## Contribution
- Feature branches are used for major upgrades and changes.
- Issues and pull requests are tracked on GitHub.

## License
This project is licensed under the MIT License.
22 changes: 22 additions & 0 deletions docs/UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Upgrade Guide

## Upgrading to .NET 10.0

- Update the `<TargetFramework>` in all .csproj files to `net10.0`.
- Update all dependencies to their latest stable versions (e.g., Newtonsoft.Json 13.0.3).
- Run `dotnet restore` and `dotnet build` to ensure compatibility.
- Run all tests to verify functionality.

## Project Structure
- Main library: `src/HttpClientServiceHelper/`
- Tests: `src/HttpClientServiceHelper.Tests/`
- Models: `src/HttpClientServiceHelper/Models/`

## Troubleshooting
- If you encounter build errors, check for breaking changes in .NET or dependencies.
- Review the official .NET migration documentation for additional guidance.

## Contribution Workflow
- Use feature branches for upgrades and major changes.
- Open a pull request and link to the relevant issue.
- Ensure all tests pass before merging.
11 changes: 6 additions & 5 deletions src/HttpClientServiceHelper.Tests/DeleteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace HttpClientServiceHelper.Tests
Expand All @@ -14,35 +15,35 @@ public class DeleteTest
List<Header> Headers = new List<Header>() { new Header() { Name = "SomeHeaderName", Value = "SomeHeaderValue" } };

[Fact]
public async void DeleteAsync()
public async Task DeleteAsync()
{
var DeleteResponse = await HttpClientHelper.DeleteAsync(Route);
Assert.NotNull(DeleteResponse);
Assert.IsType<HttpResponseMessage>(DeleteResponse);
}
[Fact]
public async void Delete_DeleteResponseAsStringAsync()
public async Task Delete_DeleteResponseAsStringAsync()
{
var DeleteResponse = await HttpClientHelper.DeleteAndGetResponseAsStringAsync(Route);
Assert.NotNull(DeleteResponse);
Assert.IsType<string>(DeleteResponse);
}
[Fact]
public async void Delete_WithToken_DeleteResponseAsStringAsync()
public async Task Delete_WithToken_DeleteResponseAsStringAsync()
{
var DeleteResponse = await HttpClientHelper.DeleteAndGetResponseAsStringAsync(Route, Token);
Assert.NotNull(DeleteResponse);
Assert.IsType<string>(DeleteResponse);
}
[Fact]
public async void DeleteAsync_WithToken()
public async Task DeleteAsync_WithToken()
{
var DeleteResponse = await HttpClientHelper.DeleteAsync(Route, Token);
Assert.NotNull(DeleteResponse);
Assert.IsType<HttpResponseMessage>(DeleteResponse);
}
[Fact]
public async void DeleteAsync_WithHeaders()
public async Task DeleteAsync_WithHeaders()
{
var DeleteResponse = await HttpClientHelper.DeleteAsync(Route, Headers);
Assert.NotNull(DeleteResponse);
Expand Down
Loading
Loading