Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/omarhimada/pype

Pype is a generic API utility which aims to expedite integration with third-parties. Includes ILogger support
https://github.com/omarhimada/pype

Last synced: about 1 month ago
JSON representation

Pype is a generic API utility which aims to expedite integration with third-parties. Includes ILogger support

Awesome Lists containing this project

README

        

# Pype
Pype is a generic API utility which aims to expedite integration with third-parties. Includes ILogger support

![Nuget](https://img.shields.io/nuget/dt/Flopype?logo=nuget&style=flat-square)

***Breaking changes:*** *version 1.1.5 includes a refactoring of the generics implementation.*

**https://www.nuget.org/packages/FloPype/**

### GET example:
```` C#
// Make a fitting to get animals from a zoo API
Fitting animalsFitting = new Fitting
{
ApiBasePath = "https://the-zoo.com",
RequestSuffix = "/api/animals/123",
ContentType = "application/json",
Method = "GET"
};

// Send the request asynchronously
FittingResponse response = await animalsFitting.SendRequest();

// Check the status of the response
switch (response.Status.Health) { ... }

// Do something with the result
Animal myAnimal = response.Result;
````

#### POST example:
```` C#
// Make a fitting to create a new animal
Fitting createAnimalFitting = new Fitting
{
ApiBasePath = "https://the-zoo.com",
RequestSuffix = "/api/animals/create",
ContentType = "application/json",
Method = "POST"
};

// Parameters can be changed at any point so you can re-use the Fitting
createAnimalFitting.Parameters = new Dictionary
{
{ "Name", "Zebra" },
{ "Stripes", true },
{ "Legs", 4 }
};

// Send the request asynchronously
FittingResponse response = await createAnimalFitting.SendRequest();

// Check the status of the response
switch (response.Status.Health) { ... }

// Do something with the result
Animal myNewAnimal = response.Result;
````

### 'OpenFaucet' to return a Stream
*Use this if you don't want to hold the response in memory for performance reasons.*
````C#
using (Stream stream = await _fitting.OpenFaucet())
using (StreamReader sr = new StreamReader(stream))
using (JsonReader reader = new JsonTextReader(sr))
{
JsonSerializer serializer = new JsonSerializer();

// * For performance: read the JSON response from a stream
SomeBigThing response = serializer.Deserialize(reader);

...
}
````