github polterguy/magic v8.4.2
Inversion of Code

latest releases: v17.3.9, v17.3.8, v17.3.7...
3 years ago

Version 8.4.2

Magic (main)

Support for PATCH endpoints in "Endpoints" menu item, including support for transmitting both
plain text and Hyperlambda, using respectively a markdown or a Hyperlambda CodeMirror editor for
supplying the [body] argument.

magic.endpoint

PATCH HTTP verb support, allowing clients to supply non-JSON types of payloads, such as for instance
Hyperlambda or plain text, etc. If you invoke a PATCH endpoint, the payload you supply, will be
passed into your Hyperlambda endpoint file as a [body] argument by default, assuming you
send your content as text/plain Content-Type.

Supporting [.accept] meta information on Hyperlambda endpoint files, declaring which Content-Type
the endpoint can handle - Which is important if you create a PATCH endpoint type, since these types
of endpoints can tolerate any types of payloads, including plain text, Hyperlambda, and "whatever"
really. If no explicit [.accept] exists on endpoint file, the default of application/json is
assumed, and returned back to client.

magic.lambda

Support for [whitelist] slot, creating a context of "whitelisted slots", which are the only
legal slots to invoke within its given lambda object. Refer to magic.lambda's documentation for
details. Also changed [vocabulary] now such that it only returns slots legally invoked by
caller, within the context, which changes of course as you create a new [whitelist] scope.

magic.lambda.slots

Supporting [whitelist] signal invocations, similar to magic.lambda, with roughly the same effect,
except of course being dynamic slots instead of statically C# created slots.

Below is an example of creating an "Inversion of Code" endpoint. Create a file in one of your modules folders, and
call it for instance "evaluate.patch.hl", and put the following content into it.

.arguments
   body:string

// Communicating that we only accept Hyperlambda to meta retriever
.accept:application/hyperlambda

// Transforming [hyperlambda] to lambda structure
hyper2lambda:x:@.arguments/*/body

// Adding given lambda into [.lambda] beneath
add:x:./*/whitelist/*/.lambda
   get-nodes:x:@hyper2lambda/*

// Whitelisting only safe keywords
whitelist
   vocabulary
      add
      unwrap
      return
      vocabulary
      slots.vocabulary
      signal:magic.google.translate
   .lambda

To evaluate the endpoint, use for instance Postman or the "Endpoints" menu item in your dashboard, and pass in the following payload to it for instance.

signal:magic.google.translate
   text:Hello World, this is cool
   src-lang:en
   dest-lang:es
unwrap:x:+/*
return
   result:x:@signal

Don't miss a new magic release

NewReleases is sending notifications on new releases.