Skip to content

Meir017/vscode-restclient-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

44 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RESTClient.NET

CI codecov RESTClient.NET.Core RESTClient.NET.Testing

A comprehensive C# library for parsing HTTP files with full VS Code REST Client compatibility and ASP.NET Core integration testing capabilities.

✨ Features

  • πŸ”„ VS Code REST Client Compatibility - Full support for standard # @name format
  • 🎲 System Variables - Built-in variables ({{$guid}}, {{$randomInt}}, {{$timestamp}}, {{$datetime}})
  • βœ… Enhanced Expectations - Parse # @expect-* comments for automated testing
  • πŸ” Name-Based API - Complete request lookup and validation
  • πŸ›‘οΈ Robust Error Handling - Detailed validation with clear error messages
  • πŸ§ͺ ASP.NET Core Integration - Full testing framework with WebApplicationFactory support

πŸ“¦ Packages

Package Version Description
RESTClient.NET.Core NuGet Core HTTP file parsing library
RESTClient.NET.Testing NuGet ASP.NET Core integration testing framework

πŸš€ Quick Start

Installation

# Core library
dotnet add package RESTClient.NET.Core

# Testing framework  
dotnet add package RESTClient.NET.Testing

Basic Usage

using RESTClient.NET.Core;

var parser = new HttpFileParser();
var httpFile = await parser.ParseAsync("requests.http");

// Get request by name
var loginRequest = httpFile.GetRequestByName("login");
Console.WriteLine($"Method: {loginRequest.Method}");
Console.WriteLine($"URL: {loginRequest.Url}");

// Access expectations
foreach (var expectation in loginRequest.Metadata.Expectations)
{
    Console.WriteLine($"Expectation: {expectation.Type} = {expectation.Value}");
}

ASP.NET Core Integration Testing

using RESTClient.NET.Testing;
using RESTClient.NET.Testing.Assertions;
using Microsoft.AspNetCore.Mvc.Testing;
using Xunit;

public class ApiIntegrationTests : HttpFileTestBase<Program>
{
    public ApiIntegrationTests(WebApplicationFactory<Program> factory) : base(factory) { }

    protected override string GetHttpFilePath() => "HttpFiles/api-requests.http";

    [Theory]
    [MemberData(nameof(HttpFileTestData))]
    public async Task ExecuteRequest_ShouldMeetExpectations(HttpTestCase testCase)
    {
        // Arrange
        var client = Factory.CreateClient();
        var requestMessage = testCase.ToHttpRequestMessage();

        // Act
        var response = await client.SendAsync(requestMessage);

        // Assert - Framework automatically validates expectations
        await HttpResponseAssertion.AssertResponse(response, testCase.ExpectedResponse);
    }

    [Fact]
    public async Task GetSpecificRequest_ShouldWork()
    {
        // Arrange
        var client = Factory.CreateClient();
        var testCase = GetTestCase("login");

        // Act
        var response = await client.SendAsync(testCase.ToHttpRequestMessage());

        // Assert
        Assert.Equal(200, (int)response.StatusCode);
    }
}

HTTP File Example

@baseUrl = https://api.example.com

# @name login
# @expect status 200
# @expect header Content-Type application/json
# @expect body-contains "token"
POST {{baseUrl}}/auth/login HTTP/1.1
Content-Type: application/json
X-Request-ID: {{$guid}}

{
    "username": "user@example.com",
    "password": "secure_password",
    "sessionId": "{{$randomInt 1000 9999}}"
}

πŸ“– Documentation

Getting Started

Reference

Additional Resources

πŸ§ͺ Testing

# Run all tests
dotnet test

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

# Build entire solution
dotnet build vscode-restclient-dotnet.slnx --configuration Release

πŸ“‹ Requirements

  • .NET 8+ (primary target)
  • .NET Standard 2.0 (for broader compatibility)
  • VS Code REST Client format compatibility

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes and add tests
  4. Ensure all tests pass (dotnet test)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❀️ for the .NET community

About

Parsing the http file defined by https://github.com/Huachao/vscode-restclient and using it for aspnetcore integration tests

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published