仓颉开发一个webapi接口

仓颉开发一个webapi接口

from net import http.ServerBuilder,http.FuncHandler
main(){
let server = ServerBuilder().addr("127.8.8.1").port(8888).build()server.distributor.register("/index", FuncHandler((httpContext =>httpContext.responseBuilder.body("hello cangjie!")
}))
server.serve()
}

  

import net.http.ServerBuilder

main () {
    // 1. 构建 Server 实例
    let server = ServerBuilder()
                        .addr("127.0.0.1")
                        .port(8080)
                        .build()
    // 2. 注册 HttpRequestHandler
    server.distributor.register("/index", {httpContext =>
        httpContext.responseBuilder.body("Hello 仓颉!")
    })
    // 3. 启动服务
    server.serve()
}

 

posted @ 2024-08-04 19:23  txwtech  阅读(68)  评论(0编辑  收藏  举报