하이퍼람다 과정 101
색인
하이퍼람다 코드
아래에서 과정 중에 생성하는 일부 스니펫 및 HTTP 끝점을 찾을 수 있습니다. 그들이 하는 일을 이해하려면 위의 비디오 과정을 시청하고 과정에서 사용할 때 관련 스니펫을 다시 참조하십시오.
튜토리얼-01-01
.foo
foo1:bar1
foo2:bar2
foo3:bar3
.foo2
foo4:bar4
foo5:bar5
.dest
for-each:x:@.foo/*
add:x:@.dest
get-nodes:x:@.dp/#
튜토리얼-02-01
.lambda
http.get:"https://microsoft.com"
if
eq:x:@http.get
.:int:200
.lambda
log.info:Microsoft.com seems to be fine!
else
log.error:Microsoft.com is NOT OK!!
lambda2hyper:x:@.lambda/*
data.connect:code
data.create
table:snippets
values
content:x:@lambda2hyper
튜토리얼-02-02
.lambda
data.connect:code
data.read
table:snippets
columns
content
limit:-1
for-each:x:@data.read/*/*
add:x:@.lambda
hyper2lambda:x:@.dp/#
eval:x:@.lambda
튜토리얼-02-03
/*
* Script that formats all Hyperlambda files recursively within
* the specified folder.
*/
.folder:/modules/northwind/
io.file.list-recursively:x:-
for-each:x:-/*
if
strings.ends-with:x:@.dp/#
.:.hl
.lambda
io.file.load:x:@.dp/#
hyper2lambda:x:-
comments:true
remove-nodes:x:@hyper2lambda/*/auth.ticket.verify
lambda2hyper:x:@hyper2lambda/*
comments:true
io.file.save:x:@.dp/#
get-value:x:@lambda2hyper
튜토리얼-02-04
/*
* Script that formats all Hyperlambda files recursively within
* the specified folder.
*/
.folder:/modules/northwind/
io.file.list-recursively:x:-
for-each:x:-/*
if
strings.ends-with:x:@.dp/#
.:.hl
.lambda
io.file.load:x:@.dp/#
hyper2lambda:x:-
comments:true
insert-before:x:@hyper2lambda/*/data.connect
.
auth.ticket.verify:admin, root, guest, foo-bar
lambda2hyper:x:@hyper2lambda/*
comments:true
io.file.save:x:@.dp/#
get-value:x:@lambda2hyper
튜토리얼-04-01
slots.create:foo
math.add:x:@.arguments/0
get-value:x:@.arguments/1
return:x:-
tutorial-04-02
slots.create:foo
math.add:x:@.arguments/0
get-value:x:@.arguments/1
튜토리얼-05-01
/*
* Creates 4 fire and forget threads.
*/
fork
http.get:"https://aista.com"
fork
http.get:"http://microsoft.com"
fork
http.get:"https://google.com"
fork
http.get:"https://dzone.com"
/*
* Creates 4 threads and waits for all threads to return
* before it proceeds.
*/
join
fork
http.get:"https://aista.com"
fork
http.get:"http://microsoft.com"
fork
http.get:"https://google.com"
fork
http.get:"https://dzone.com"
/*
* Creates 4 sequentially invoked HTTP GET invocations.
*/
http.get:"https://aista.com"
http.get:"http://microsoft.com"
http.get:"https://google.com"
http.get:"https://dzone.com"
튜토리얼-05-02
// Thread number 1, loads a file, concatenates to it, and saves the file again.
fork
.lambda1
semaphore:semaphore-thread
io.file.load:/foo.txt
strings.concat
get-value:x:@io.file.load
.:"Appended by lambda object 1\r\n"
io.file.save:/foo.txt
get-value:x:@strings.concat
eval:x:@.lambda1
// Thread number 2, loads a file, concatenates to it, and saves the file again.
fork
.lambda2
semaphore:semaphore-thread
io.file.load:/foo.txt
strings.concat
get-value:x:@io.file.load
.:"Appended by lambda object 2\r\n"
io.file.save:/foo.txt
get-value:x:@strings.concat
eval:x:@.lambda2
HTTP 끝점
아래에서 과정 중에 생성하는 Hyperlambda HTTP 끝점을 찾을 수 있습니다.
tutorial01.get.hl
.arguments
name:string
age:int
strings.concat
.:"Hello there "
get-value:x:@.arguments/*/name
.:", you are "
get-value:x:@.arguments/*/age
.:" years old"
unwrap:x:+/*
return
result:x:@strings.concat
tutorial02.get.hl
.foo
foo1:bar1
foo2:bar2
foo3:bar3
.foo2
foo4:bar4
foo5:bar5
.dest
for-each:x:@.foo/*
add:x:@.dest
get-nodes:x:@.dp/#
lambda2hyper:x:../*
log.info:x:-
return:x:@.dest/*
tutorial03.get.hl
/*
* Example of how to secure your API endpoint using JWT and
* the internals of Hyperlambda's JWT token slots.
*/
// Throws an exception unless user belongs to root or admin role.
auth.ticket.verify:root, admin
return
result:Hello World from a secure endpoint
tutorial04.get.hl
.data
foo1:bar1
foo2:bar2
unwrap:x:+/*
return
value1:x:@.data/*/foo1
value2:x:@.data/*/foo2
tutorial05.get.hl
.arguments
name:string
if
eq:x:@.arguments/*/name
.:Thomas
.lambda
return
result:Hi boss!
else-if
eq:x:@.arguments/*/name
.:John
.lambda
return
result:Hi John!
else
return
result:Hi stranger!
tutorial06.post.hl
/*
* Allows the caller to (securely) pass in Hyperlambda to
* our endpoint and execute it, allowing the caller to
* specify the logic to execute, and what data to return.
*/
.arguments
body:*
.accept:application/hyperlambda
// Loading Hyperlambda from [body] argument.
io.stream.read:x:@.arguments/*/body
// Ensuring we return raw Hyperlambda to caller.
response.headers.set
Content-Type:application/hyperlambda
// Transforming to Hyperlambda and adding lambda into [.lambda] object.
add:x:+/*/.lambda
hyper2lambda:x:@io.stream.read
// [whitelist] invocation preventing malicious slots from being executed.
whitelist
// Slots caller is allowed to invoke.
vocabulary
add
insert-before
insert-after
set-value
set-name
vocabulary
slots.vocabulary
for-each
while
if
else-if
else
strings.concat
return
return-nodes
unwrap
.lambda
// Returning lambda object to caller.
lambda2hyper:x:@whitelist/*
return:x:-
인터셉터.hl
data.connect:crm
.interceptor
foo.get.hl
data.select:select * from status
return:x:-/*
Reference
이 문제에 관하여(하이퍼람다 과정 101), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/polterguy/hyperlambda-course-101-52k9텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)