|
| 1 | +[](https://www.triggerme.io) |
1 | 2 | [](https://dev.azure.com/TriggerHelper/CSharpRequestLibrary/_build/latest?definitionId=1) |
| 3 | +[](https://www.nuget.org/packages/TriggerMe.Request) |
2 | 4 |
|
3 | | -# CSharpRequestLibrary |
4 | | -C# Library to make requests to the TriggerMe Forwarder/Router |
| 5 | +# TriggerMe C# Request Library |
| 6 | +C# Library to make requests to the TriggerMe Forwarder/Router. TriggerMe provides an API proxy to Test, Forward and Route requests. |
| 7 | + |
| 8 | +TriggerMe provides a serverless proxy to help diagnose API request issues, manage retries and mock responses. |
| 9 | + |
| 10 | +# Usage |
| 11 | +To forward a HTTP Post request: |
| 12 | + |
| 13 | +```csharp |
| 14 | +var content = new { message = "Hello World" }; |
| 15 | +var strContent = new StringContent(JsonConvert.SerializeObject(content), Encoding.UTF8, "application/json"); |
| 16 | + |
| 17 | +Options.ApiKey = "[[Your API Key]]"; |
| 18 | +var client = new ForwardRequestClient(); |
| 19 | +var response = await client.PostAsync("[[TargetUrl]]", strContent); |
| 20 | +Console.WriteLine(response.RequestId); |
| 21 | +``` |
| 22 | + |
| 23 | +You can check the status of the request using the `RequestId` returned from the response object. |
| 24 | + |
| 25 | +```csharp |
| 26 | +var requestStatus = new ForwardRequestStatus(); |
| 27 | +var update = await requestStatus.CheckRequestAsync(response.RequestId); |
| 28 | +Console.WriteLine(update.Result); |
| 29 | +``` |
| 30 | + |
| 31 | +You can download the Request or Response body by accessing the `BlobUri` property of either `RequestLog.BlobUri` or `RequestLog.RetryRecords[].BlobUri`. |
| 32 | + |
| 33 | +***Note:** These Blob URIs are timed so should not be cached* |
| 34 | + |
| 35 | +```csharp |
| 36 | +// Downloading the request blob |
| 37 | +var req = await update.Request.DownloadBlobAsStringAsync(); |
| 38 | +Console.WriteLine(req); |
| 39 | + |
| 40 | +// Downloading the final response blob |
| 41 | +var response = await update.RetryRecords.Last().DownloadBlobAsStringAsync(); |
| 42 | +Console.WriteLine(response); |
| 43 | +``` |
| 44 | + |
| 45 | +# Building |
| 46 | +Prerequisites |
| 47 | +- Microsoft .NET Core 2.2 SDK |
| 48 | + |
| 49 | +To build the solution and the tests |
| 50 | +``` |
| 51 | +dotnet build |
| 52 | +``` |
| 53 | + |
| 54 | +To build the NuGet package |
| 55 | +``` |
| 56 | +cd src/TriggerMe/Request |
| 57 | +dotnet pack -c Release |
| 58 | +``` |
| 59 | + |
| 60 | +# License |
| 61 | +Copyright © 2018 TriggerMe (Stellar Tech Limited) |
| 62 | + |
| 63 | +This program is free software: you can redistribute it and/or modify it under the terms of the Apache 2.0 license. |
| 64 | + |
| 65 | +# Legal |
| 66 | +By submitting a Pull Request, you disavow any rights or claims to any changes submitted to the TriggerMe project and assign the copyright of those changes to Stellar Tech Limited. |
| 67 | + |
| 68 | +If you cannot or do not want to reassign those rights (your employment contract for your employer may not allow this), you should not submit a PR. Open an issue and someone else can do the work. |
| 69 | + |
| 70 | +This is a legal way of saying "If you submit a PR to us, that code becomes ours". 99.9% of the time that's what you intend anyways; we hope it doesn't scare you away from contributing. |
0 commit comments