A .NET Standard 2.1 client library for searching GitHub code using the grep.app API.
Created by the team at Ivy - The ultimate framework for creating internal business app in pure C#.
- Simple, clean API for GitHub code search
- Built-in rate limiting and error handling
- Comprehensive exception handling
- Strongly-typed request and response models
- Cross-platform compatibility (.NET Standard 2.1 - works with .NET Core 3.0+, .NET Framework 4.8+, .NET 5+)
Install the package from NuGet:
dotnet add package Ivy.GrepAppusing Ivy.GrepApp;
// Create a client
using var client = new GrepAppSearchClient();
// Create a search request
var request = new SearchRequest("async function")
{
Language = "JavaScript",
Repository = "nodejs/node",
Path = "lib/",
ResultLimit = 10
};
// Execute the search
var response = await client.SearchAsync(request);
// Access results
Console.WriteLine($"Found {response.Summary.TotalResults} results");
foreach (var repo in response.ResultsByRepository)
{
Console.WriteLine($"Repository: {repo.Repository}");
foreach (var file in repo.Files)
{
Console.WriteLine($" File: {file.FilePath} ({file.TotalMatches} matches)");
}
}The main client class for interacting with the grep.app API.
GrepAppSearchClient()- Creates a new client with default HttpClientGrepAppSearchClient(HttpClient httpClient)- Creates a client with provided HttpClient
SearchAsync(SearchRequest request, CancellationToken cancellationToken = default)- Executes a search and returns results
Represents a search query with optional filters.
Query(string, required) - The search query (max 1000 characters)Language(string?, optional) - Filter by programming language (max 50 characters)Repository(string?, optional) - Filter by repository in format "owner/repo" (max 100 characters)Path(string?, optional) - Filter by file path (max 200 characters)ResultLimit(int?, optional) - Limit number of results (1-100, default: 10)
Contains the search results and metadata.
Query- The original search querySummary- Summary information including total results countResultsByRepository- Array of results grouped by repository
The library provides specific exception types:
GrepApiException- Base exception for API errorsGrepApiTimeoutException- Thrown when requests timeoutGrepApiRateLimitException- Thrown when rate limits are exceeded
try
{
var response = await client.SearchAsync(request);
}
catch (GrepApiRateLimitException)
{
// Handle rate limiting
await Task.Delay(TimeSpan.FromMinutes(1));
}
catch (GrepApiTimeoutException)
{
// Handle timeout
Console.WriteLine("Request timed out, try again later");
}
catch (GrepApiException ex)
{
// Handle other API errors
Console.WriteLine($"API error: {ex.Message}");
}Important: By using this library, you acknowledge and agree to the following:
- You must be at least 13 years old to use this service
- You agree to comply with grep.app's Terms of Service
- This library accesses a third-party service (grep.app) operated by Vercel
- The service is provided "AS IS" with no warranties
- You are responsible for evaluating all search results for correctness
- Automated or scripted usage may be restricted by the service provider
- You must comply with all applicable trade laws and export controls
Disclaimer: This is an unofficial third-party client library. The authors are not affiliated with Vercel or the grep.app service. Users are responsible for ensuring their usage complies with all applicable terms of service and legal requirements.
This library is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please ensure all tests pass and follow the existing code style.
For issues with this library, please open an issue on GitHub. For issues with the grep.app service itself, please contact Vercel directly.