Skip to content

Latest commit

 

History

History
93 lines (75 loc) · 3.63 KB

README.md

File metadata and controls

93 lines (75 loc) · 3.63 KB

Replit

An async and lightweight C# library for interacting with Replit APIs.

Usage

Provides an easy interface for interacting with Replit APIs. Currently distributed packages:

  • Replit.GraphQL (NuGet) (GitHub) - Wrapper for the GraphQL API.

To get started, add the library into your solution with either the NuGet Package Manager or the dotnet CLI.

dotnet add package Replit.GraphQL

For the primary classes to become available, import the used namespace.

using Replit.GraphQL;

Warning
Certain actions require you to pass a valid session identifier (connect.sid) cookie. You can obtain this from the browser Developer Tools while logged in.
Unsure of how to obtain this value? See this guide written by RayhanADev.
If you are on mobile, you can alternatively use this web based form made by IroncladDev.

Features

  • Built for .NET 6 and .NET 7
  • Fully async
  • Extensive XML documentation
  • No external dependencies (uses integrated HTTP and JSON)
  • Custom exceptions for advanced catching
  • Execute single or bulk Replit GraphQL queries

Example

Under the Example directory you can find a working demo project that implements this library.

Code Samples

Initializing a new GraphQL client with a valid session identifier cookie

string sid = "s%3Bew5ttAQuBlAANjIh8ABSoTTtZ75-7AbH.ohRBI9wNPwOHED7GLltPBrOS975gxqATe1aL6y%9N3%2Fla";
ReplitGraphQLClient client = new(sid, "Example Application");

Executing a single query

string userByUsername = @"
    query userByUsername($username: String!) {
        user: userByUsername(username: $username) {
            id
            bio
            firstName
            lastName
            timeCreated
    }
}";

User user = (await client.Execute<UserContainer>(userByUsername, new Dictionary<string, object>()
{
    {
        "username", "akac"
    }
}))?.User;

Executing bulk queries

Repl[] repls = (await client.BulkExecute<ReplContainer>(new GraphQLParameters[]
{
    new(replByUrl, new() { { "url", "https://replit.com/@amasad/TroubledPersonalBaitware" } }),
    new(replByUrl, new() { { "url", "https://replit.com/@amasad/my-fun-new-app" } }),
    new(replByUrl, new() { { "url", "https://replit.com/@amasad/comic-sans" } })
}))?.Select(data => data.Repl).ToArray();

Console.WriteLine($"Retrieved {repls.Length} repls back");

foreach (Repl repl in repls) Console.WriteLine($"=> {repl.Title} ({repl.Id}) was created at {repl.TimeCreated}");

Available Methods

  • Task<GraphQLContainer[]> BulkExecuteRaw(GraphQLParameters[] parameters, JsonSerializerOptions options = null)
  • Task<GraphQLContainer> ExecuteRaw(string query, Dictionary<string, object> variables = null, string operationName = null, JsonSerializerOptions options = null)
  • Task<T[]> BulkExecute(GraphQLParameters[] parameters, bool suppressErrors = false, JsonSerializerOptions options = null)
  • Task<T> Execute(string query, Dictionary<string, object> variables = null, bool suppressErrors = false, string operationName = null, JsonSerializerOptions options = null)

References