magic.lambda.http 11.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package magic.lambda.http --version 11.0.5                
NuGet\Install-Package magic.lambda.http -Version 11.0.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="magic.lambda.http" Version="11.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add magic.lambda.http --version 11.0.5                
#r "nuget: magic.lambda.http, 11.0.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install magic.lambda.http as a Cake Addin
#addin nuget:?package=magic.lambda.http&version=11.0.5

// Install magic.lambda.http as a Cake Tool
#tool nuget:?package=magic.lambda.http&version=11.0.5                

Invoking HTTP endpoints from Hyperlambda

This project provides HTTP invocation capabilities for Magic and Hyperlambda. More specifically the project contains the following 5 slots.

  • [http.get] - Returns some resource using the HTTP GET verb towards the specified URL
  • [http.delete] - Deletes some resource using the HTTP DELETE verb
  • [http.post] - Posts some resources to some URL using the HTTP POST verb
  • [http.put] - Puts some resources to some URL using the HTTP PUT verb
  • [http.patch] - Patches some resources to some URL using the HTTP PATCH verb

The [http.put], [http.post] and [http.patch] slots requires you to provide a [payload] or [filename] argument that will be transferred to the endpoint as is. All 5 endpoints can (optionally) take a [token] arguments, which will be transferred as a Bearer Authorization token to the endpoint in the Authorization header of your request. If you provide a [filename] argument, this is assumed to be a file relatively found within your "/files/" folder somewhere. Below is an example of retrieving the document found at the specified URL by creating an HTTP GET request.

http.get:"https://google.com"

The above will result in something resembling the following.

http.get:int:200
   headers
      Cache-Control:no-store, must-revalidate, no-cache, max-age=0
      Pragma:no-cache
      Date:"Mon, 29 Nov 2021 06:11:01 GMT"
      // ... etc ...
   content:"... content here ..."

The status code of the request is returned as the value of [http.xxx], headers returned by the server can be found in [headers] as a key/value pair, and [content] contains the actual content response object returned by the server.

HTTP headers

If you want to have more control over your HTTP request, you can also explicitly add your own [headers] collection, which will become the HTTP request's headers, where the header name is the name of the node, and its value is the value of the node. Below is an example.

http.get:"https://google.com"
   headers
      Accept:text/html

If you don't add an explicit [headers] collection the invocation will assume your request payload and accepted response is JSON. If you want to change this you'll have to add at least one header to your request, at which point the default headers will not be applied.

POSTing, PUTting, and PATCHing data

The POST, PUT and PATCH slots, requires a [payload] argument, or a [filename] argument, that becomes the body of the request. Below is an example illustrating how to create a POST request, with a Bearer token to access the end resource.

http.post:"https://some-url.com"
   token:qwerty_secret_JWT_token_goes_here
   payload:some mumbo jumbo payload, typically JSON and not text though ...

Notice - If you want to submit a large file to some endpoint, without loading the file into memory first, you should rather use [filename] instead of [payload]. This ensures the file is submitted to your endpoint without loading it into memory first.

http.post:"https://some-url.com"
   filename:/README.md

Automatic conversion

You can also automatically convert the resulting response object to a lambda object if you have a registered conversion function, and you provide a [convert] argument, and set its value to boolean true. Below is an example.

http.get:"https://jsonplaceholder.typicode.com/posts"
   convert:bool:true

The above will result in something resembling the following.

http.get:int:200
   headers
      Date:"Mon, 29 Nov 2021 06:19:29 GMT"
      Transfer-Encoding:chunked
      Connection:keep-alive
      // ... etc ...
   content
      .
         userId:long:1
         id:long:1
         title:sunt aut facere repellat provident occaecati excepturi optio reprehenderit
         body:qwerty1
      .
         userId:long:1
         id:long:2
         title:qui est esse
         body:qwerty2
      // ... etc ...

The project contains automatic conversions for the following types out of the box, but you can easily register your own C# based conversion types for specific "Content-Type" values.

  • application/json
  • application/x-json
  • application/hyperlambda
  • application/x-hyperlambda
  • application/www-form-urlencoded
  • application/x-www-form-urlencoded

You can also convert a semantic lambda object to the correct request content in a similar fashion, by instead of providing a value to your [payload] node provide a lambda object such as illustrated below.

.userId:int:1
http.post:"https://jsonplaceholder.typicode.com/posts"
   payload
      id:int:1
      userId:x:@.userId

The above will transform your payload to a JSON object automatically for you, and also unwrap any expressions found in your lambda object before JSON transformation is applied. Automatic transformation will only be applied if you've got a transformation function registered. If you want to extend the list of supported content types to automatically transform back and forth to, you can use either Magic.Http.AddRequestHandler or MagicHttp.AddResponseHandler to add support for your own automatic transformation for both the request payload and/or the response content.

Notice - The [payload] node above must have a null value, otherwise the slot will prioritise the value, and not attempt to transform from a semantic lambda object in any ways. Values in your [payload] will be transferred as is, and you can provide byte[] arrays, streams or strings as the value of your [payload] node.

Notice - Both the URL encoded request transformer and the JSON request transformer will automatically evaluate expressions in your semantic [payload] object, but this is not true for the Hyperlambda request transformer, since in Hyperlambda it might make sense to actually pass in expressions to the endpoint. Below is an example of how to semantically pass in a Hyperlambda object to some URL.

http.post:"https://foo.com/hyperlambda-endpoint"
   headers
      Content-Type:application/hyperlambda
   payload
      .foo
         .:Thomas
         .:John
      for-each:x:@.foo
         // ... etc ...

The above will automatically serialize your lambda object as Hyperlambda, since the Content-Type is of a type supported by the automatic conversion functions, and transfer the request as a string to the endpoint, preserving expressions as is without unwrapping them before transmitting your [payload].

Project website

The source code for this repository can be found at [github.com/polterguy/magic.lambda.http](https://github.com/polterguy/magic.lambda.http, and you can provide feedback, provide bug reports, etc at the same place.

Quality gates

  • Build status
  • Quality Gate Status
  • Bugs
  • Code Smells
  • Coverage
  • Duplicated Lines (%)
  • Lines of Code
  • Maintainability Rating
  • Reliability Rating
  • Security Rating
  • Technical Debt
  • Vulnerabilities
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on magic.lambda.http:

Package Downloads
magic.library

Helper project for Magic to wire up everything easily by simply adding one package, and invoking two simple methods. When using Magic, this is (probably) the only package you should actually add, since this package pulls in everything else you'll need automatically, and wires up everything sanely by default. To use package go to https://polterguy.github.io

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
17.2.0 433 1/22/2024
17.1.7 186 1/12/2024
17.1.6 158 1/11/2024
17.1.5 176 1/5/2024
17.0.1 190 1/1/2024
17.0.0 370 12/14/2023
16.11.5 353 11/12/2023
16.9.0 331 10/9/2023
16.8.4 249 9/25/2023
16.8.0 201 9/24/2023
16.7.51 155 9/24/2023
16.7.50 197 9/23/2023
16.7.0 402 7/11/2023
16.6.13 231 7/6/2023
16.4.1 362 7/2/2023
16.4.0 398 6/22/2023
16.3.1 341 6/7/2023
16.3.0 331 5/28/2023
16.1.9 628 4/30/2023
15.10.11 478 4/13/2023
15.9.1 612 3/27/2023
15.9.0 462 3/24/2023
15.8.2 501 3/20/2023
15.7.0 394 3/6/2023
15.5.0 1,588 1/28/2023
15.2.0 687 1/18/2023
15.1.0 1,150 12/28/2022
14.5.7 709 12/13/2022
14.5.5 787 12/6/2022
14.5.1 671 11/23/2022
14.5.0 603 11/18/2022
14.4.5 704 10/22/2022
14.4.1 745 10/22/2022
14.4.0 660 10/17/2022
14.3.1 1,279 9/12/2022
14.3.0 658 9/10/2022
14.1.3 904 8/7/2022
14.1.2 673 8/7/2022
14.1.1 665 8/7/2022
14.0.14 692 7/26/2022
14.0.12 696 7/24/2022
14.0.11 639 7/23/2022
14.0.10 658 7/23/2022
14.0.9 627 7/23/2022
14.0.8 742 7/17/2022
14.0.5 810 7/11/2022
14.0.4 786 7/6/2022
14.0.3 725 7/2/2022
14.0.2 688 7/2/2022
14.0.0 875 6/25/2022
13.4.0 2,076 5/31/2022
13.3.4 1,458 5/9/2022
13.3.0 975 5/1/2022
13.2.0 1,206 4/21/2022
13.1.0 1,028 4/7/2022
13.0.0 743 4/5/2022
11.0.5 1,454 3/2/2022
11.0.4 801 2/22/2022
11.0.3 749 2/9/2022
11.0.2 791 2/6/2022
11.0.1 779 2/5/2022
10.0.21 771 1/28/2022
10.0.20 774 1/27/2022
10.0.19 769 1/23/2022
10.0.18 751 1/17/2022
10.0.15 952 12/31/2021
10.0.14 543 12/28/2021
10.0.13 605 12/23/2021
10.0.7 1,253 12/22/2021
10.0.5 718 12/18/2021
10.0.2 647 12/14/2021
10.0.0 616 12/6/2021
9.9.9 1,136 11/29/2021
9.9.6 4,534 11/24/2021
9.9.5 476 11/23/2021
9.9.4 817 11/21/2021
9.9.3 584 11/9/2021
9.9.2 637 11/4/2021
9.9.0 729 10/30/2021
9.8.9 691 10/29/2021
9.8.7 638 10/27/2021
9.8.6 634 10/27/2021
9.8.5 719 10/26/2021
9.8.3 914 10/24/2021
9.8.2 414 10/24/2021
9.8.0 843 10/20/2021
9.7.9 642 10/19/2021
9.7.5 1,505 10/14/2021
9.7.0 862 10/9/2021
9.6.6 1,257 8/14/2021
9.3.6 3,974 6/21/2021
9.2.0 2,842 5/26/2021
9.1.4 1,295 4/21/2021
9.1.0 1,059 4/14/2021
9.0.0 891 4/5/2021
8.9.9 1,022 3/30/2021
8.9.3 1,542 3/19/2021
8.9.2 1,014 1/29/2021
8.9.1 1,031 1/24/2021
8.9.0 1,114 1/22/2021
8.6.9 2,951 11/8/2020
8.6.6 1,951 11/2/2020
8.6.0 3,930 10/28/2020
8.5.0 1,864 10/23/2020
8.4.0 5,543 10/13/2020
8.3.2 1,204 10/11/2020
8.3.1 1,932 10/5/2020
8.3.0 1,243 10/3/2020
8.2.2 2,023 9/26/2020
8.2.1 1,337 9/25/2020
8.2.0 1,370 9/25/2020
8.1.17 6,604 9/13/2020
8.1.16 631 9/13/2020
8.1.15 1,911 9/12/2020
8.1.11 2,476 9/11/2020
8.1.10 1,294 9/6/2020
8.1.9 1,315 9/3/2020
8.1.8 1,288 9/2/2020
8.1.7 1,203 8/28/2020
8.1.4 1,203 8/25/2020
8.1.3 1,268 8/18/2020
8.1.2 1,217 8/16/2020
8.1.1 1,253 8/15/2020
8.1.0 577 8/15/2020
8.0.1 2,636 8/7/2020
8.0.0 1,210 8/7/2020
7.0.1 1,349 6/28/2020
7.0.0 1,240 6/28/2020
5.0.0 7,317 2/25/2020
4.0.4 7,761 1/27/2020
4.0.3 1,264 1/27/2020
4.0.2 1,399 1/16/2020
4.0.1 1,365 1/11/2020
4.0.0 1,357 1/5/2020
3.1.0 6,173 11/10/2019
3.0.2 1,914 10/28/2019
3.0.1 2,007 10/26/2019
3.0.0 1,153 10/23/2019
2.0.1 8,178 10/15/2019
2.0.0 1,629 10/13/2019
1.1.9 1,344 10/11/2019
1.1.8 1,323 10/10/2019
1.1.7 580 10/9/2019
1.1.6 573 10/7/2019
1.1.5 586 10/6/2019
1.1.4 580 10/6/2019
1.1.2 599 10/5/2019
1.0.0 654 9/26/2019