Skip to content

dlmelendez/paypalhttp_dotnet

 
 

Repository files navigation

ElCamino.PayPalHttp

Improved regex and threading performance and current .NET frameworks over deprecated/forked PayPalHttp library.

PayPal HttpClient

PayPalHttp is a generic HTTP Client used with generated server SDKs.

In it's simplest form, an HttpClient exposes an Execute method which takes an HTTP request, executes it against the domain described in an Environment, and returns an HTTP response.

Environment

An Environment describes a domain that hosts a REST API, against which an HttpClient will make requests. Environment is a simple interface that wraps one method, BaseUrl.

var env = new Environment('https://example.com')

Requests

HTTP requests contain all the information needed to make an HTTP request against the REST API. Specifically, one request describes a path, a method, any path/query/form parameters, headers, attached files for upload, and body data.

These objects are constructed in code generated by the sdkgen project. Instructions for using generated HTTP request subclasses is provided in that project.

Responses

HTTP responses contain information returned by a server in response to a request as described above. They are simple objects which contain a status code, headers, and any data returned by the server.

var client = new HttpClient(env);

var request = new HttpRequest("/", HttpMethod.Get);
request.Body = "some data";

var response = await client.Execute(request);

var statusCode = response.StatusCode;
var headers = response.Headers;
var data = response.Result<String>();

Injectors

Injectors are blocks that can be used for executing arbitrary pre-flight logic, such as modifying a request or logging data. Injectors are attached to an HttpClient using the AddInjector method.

The HttpClient executes its injectors in a first-in, first-out order, before each request.

class LogInjector : IInjector
{
	public void Inject(HttpRequest request)
    {
        // Do some logging here
    }
}

var logInjector = new LogInjector();
client.AddInjector(logInjector);
...

Error Handling

HttpClient#Execute may throw an HttpException if something went wrong during the course of execution. If the server returned a non-200 response, HttpException will be thrown, that will contain a status code and headers you can use for debugging.

try
{
    client.Execute(request);
}
catch (HttpException ex)
{
	var statusCode = ex.StatusCode;
	var headers = ex.Headers;
	var message = ex.response<String>();
}

License

PayPalHttp-Dotnet is open source and available under the MIT license. See the LICENSE file for more information.

Contributing

Pull requests and issues are welcome. Please see CONTRIBUTING.md for more details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 94.8%
  • Ruby 5.2%