仓颉开发一个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() }
欢迎讨论,相互学习。
cdtxw@foxmail.com