magic.lambda.http 14.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package magic.lambda.http --version 14.1.2                
NuGet\Install-Package magic.lambda.http -Version 14.1.2                
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="14.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add magic.lambda.http --version 14.1.2                
#r "nuget: magic.lambda.http, 14.1.2"                
#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=14.1.2

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

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 382 1/22/2024
17.1.7 168 1/12/2024
17.1.6 135 1/11/2024
17.1.5 159 1/5/2024
17.0.1 180 1/1/2024
17.0.0 345 12/14/2023
16.11.5 326 11/12/2023
16.9.0 310 10/9/2023
16.8.4 235 9/25/2023
16.8.0 176 9/24/2023
16.7.51 149 9/24/2023
16.7.50 166 9/23/2023
16.7.0 374 7/11/2023
16.6.13 225 7/6/2023
16.4.1 328 7/2/2023
16.4.0 367 6/22/2023
16.3.1 322 6/7/2023
16.3.0 320 5/28/2023
16.1.9 600 4/30/2023
15.10.11 456 4/13/2023
15.9.1 582 3/27/2023
15.9.0 450 3/24/2023
15.8.2 492 3/20/2023
15.7.0 372 3/6/2023
15.5.0 1,550 1/28/2023
15.2.0 665 1/18/2023
15.1.0 1,127 12/28/2022
14.5.7 700 12/13/2022
14.5.5 778 12/6/2022
14.5.1 649 11/23/2022
14.5.0 581 11/18/2022
14.4.5 682 10/22/2022
14.4.1 729 10/22/2022
14.4.0 634 10/17/2022
14.3.1 1,243 9/12/2022
14.3.0 626 9/10/2022
14.1.3 900 8/7/2022
14.1.2 648 8/7/2022
14.1.1 641 8/7/2022
14.0.14 668 7/26/2022
14.0.12 674 7/24/2022
14.0.11 618 7/23/2022
14.0.10 649 7/23/2022
14.0.9 605 7/23/2022
14.0.8 716 7/17/2022
14.0.5 791 7/11/2022
14.0.4 759 7/6/2022
14.0.3 701 7/2/2022
14.0.2 664 7/2/2022
14.0.0 841 6/25/2022
13.4.0 2,014 5/31/2022
13.3.4 1,416 5/9/2022
13.3.0 938 5/1/2022
13.2.0 1,171 4/21/2022
13.1.0 997 4/7/2022
13.0.0 721 4/5/2022
11.0.5 1,422 3/2/2022
11.0.4 774 2/22/2022
11.0.3 720 2/9/2022
11.0.2 768 2/6/2022
11.0.1 755 2/5/2022
10.0.21 743 1/28/2022
10.0.20 751 1/27/2022
10.0.19 747 1/23/2022
10.0.18 721 1/17/2022
10.0.15 913 12/31/2021
10.0.14 519 12/28/2021
10.0.13 581 12/23/2021
10.0.7 1,213 12/22/2021
10.0.5 691 12/18/2021
10.0.2 633 12/14/2021
10.0.0 590 12/6/2021
9.9.9 1,113 11/29/2021
9.9.6 4,511 11/24/2021
9.9.5 452 11/23/2021
9.9.4 795 11/21/2021
9.9.3 557 11/9/2021
9.9.2 608 11/4/2021
9.9.0 706 10/30/2021
9.8.9 668 10/29/2021
9.8.7 614 10/27/2021
9.8.6 605 10/27/2021
9.8.5 696 10/26/2021
9.8.3 880 10/24/2021
9.8.2 397 10/24/2021
9.8.0 814 10/20/2021
9.7.9 618 10/19/2021
9.7.5 1,459 10/14/2021
9.7.0 831 10/9/2021
9.6.6 1,212 8/14/2021
9.3.6 3,877 6/21/2021
9.2.0 2,781 5/26/2021
9.1.4 1,263 4/21/2021
9.1.0 1,026 4/14/2021
9.0.0 862 4/5/2021
8.9.9 1,005 3/30/2021
8.9.3 1,508 3/19/2021
8.9.2 990 1/29/2021
8.9.1 1,006 1/24/2021
8.9.0 1,090 1/22/2021
8.6.9 2,914 11/8/2020
8.6.6 1,922 11/2/2020
8.6.0 3,879 10/28/2020
8.5.0 1,833 10/23/2020
8.4.0 5,477 10/13/2020
8.3.2 1,181 10/11/2020
8.3.1 1,907 10/5/2020
8.3.0 1,217 10/3/2020
8.2.2 1,988 9/26/2020
8.2.1 1,313 9/25/2020
8.2.0 1,343 9/25/2020
8.1.17 6,557 9/13/2020
8.1.16 612 9/13/2020
8.1.15 1,867 9/12/2020
8.1.11 2,432 9/11/2020
8.1.10 1,263 9/6/2020
8.1.9 1,286 9/3/2020
8.1.8 1,270 9/2/2020
8.1.7 1,176 8/28/2020
8.1.4 1,167 8/25/2020
8.1.3 1,242 8/18/2020
8.1.2 1,189 8/16/2020
8.1.1 1,225 8/15/2020
8.1.0 558 8/15/2020
8.0.1 2,600 8/7/2020
8.0.0 1,186 8/7/2020
7.0.1 1,330 6/28/2020
7.0.0 1,209 6/28/2020
5.0.0 7,246 2/25/2020
4.0.4 7,684 1/27/2020
4.0.3 1,236 1/27/2020
4.0.2 1,374 1/16/2020
4.0.1 1,337 1/11/2020
4.0.0 1,333 1/5/2020
3.1.0 6,098 11/10/2019
3.0.2 1,876 10/28/2019
3.0.1 1,973 10/26/2019
3.0.0 1,124 10/23/2019
2.0.1 8,065 10/15/2019
2.0.0 1,593 10/13/2019
1.1.9 1,312 10/11/2019
1.1.8 1,299 10/10/2019
1.1.7 560 10/9/2019
1.1.6 555 10/7/2019
1.1.5 567 10/6/2019
1.1.4 562 10/6/2019
1.1.2 581 10/5/2019
1.0.0 637 9/26/2019