Http模块

简介: Http server基础Route对于Http模块的简单学习记录。

基础


import (
  "github.com/astaxie/beego"
  )
  func main() { 
  // now you start the beego as http server.  
  // it will listen to port 8080
  beego.Run() 
  // it will listen to 8080 
  // beego.Run("localhost") 
  // it will listen to 8089 
  // beego.Run(":8089") 
  // it will listen to 8089 
  // beego.Run("127.0.0.1:8089")}


Route


import (
  "github.com/astaxie/beego"
  )
  func main() { 
  ctrl := &MainController{} 
  // we register the path / to &MainController  
  // if we don't pass methodName as third param 
  // beego will use the default mappingMethods  
  // GET http://localhost:8080  -> Get()  
  // POST http://localhost:8080 -> Post() 
  // ...  
  beego.Router("/", ctrl) 
  // GET http://localhost:8080/health => ctrl.Health()  
  beego.Router("/health", ctrl, "get:Health") 
  // POST http://localhost:8080/update => ctrl.Update() 
  beego.Router("/update", ctrl, "post:Update")  
  // support multiple http methods. 
  // POST or GET http://localhost:8080/update => ctrl.GetOrPost() 
  beego.Router("/getOrPost", ctrl, "get,post:GetOrPost")  
  // support any http method  
  // POST, GET, PUT, DELETE... http://localhost:8080/update => ctrl.Any() 
  beego.Router("/any", ctrl, "*:Any") 
  beego.Run()
  }
  // MainController:
  // The controller must implement ControllerInterface
  // Usually we extends beego.Controllertype 
  MainController struct {
    beego.Controller
  }
  // address: http://localhost:8080 GET
  func (ctrl *MainController) Get()  {
    // beego-example/views/hello_world.html 
    ctrl.TplName = "hello_world.html" 
    ctrl.Data["name"] = "Get()" 
    // don't forget this  
    _ = ctrl.Render()
  }
  // GET http://localhost:8080/healthfunc (ctrl *MainController) Health()  {  
  // beego-example/views/hello_world.html 
  ctrl.TplName = "hello_world.html" 
  ctrl.Data["name"] = "Health()"  
  // don't forget this  
  _ = ctrl.Render()}
  // POST http://localhost:8080/update
  func (ctrl *MainController) Update()  { 
  // beego-example/views/hello_world.html 
  ctrl.TplName = "hello_world.html" 
  ctrl.Data["name"] = "Update()"  
  // don't forget this  
  _ = ctrl.Render()}
  // GET or POST http://localhost:8080/update
  func (ctrl *MainController) GetOrPost()  {  
  // beego-example/views/hello_world.html 
  ctrl.TplName = "hello_world.html" 
  ctrl.Data["name"] = "GetOrPost()" 
  // don't forget this  _ = ctrl.Render()}
  // any http method http://localhost:8080/any
  func (ctrl *MainController) Any()  {  
  // beego-example/views/hello_world.html 
  ctrl.TplName = "hello_world.html" 
  ctrl.Data["name"] = "Any()" 
  // don't forget this  
  _ = ctrl.Render()}
相关文章
|
JavaScript
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)
246 0
|
JavaScript
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)(上)
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)
295 0
|
JavaScript 前端开发 开发者
Node学习笔记:HTTP模块
总的来说,Node.js的HTTP模块是一个强大的工具,可以帮助你处理HTTP协议的各种需求。无论你是想开设自己的餐厅(创建服务器),还是想去别的餐厅点菜(发出请求),HTTP模块都能满足你的需求。
433 18
|
JavaScript 前端开发
基于 Node.js 环境,使用内置 http 模块,创建 Web 服务程序
基于 Node.js 环境,使用内置 http 模块,创建 Web 服务程序
707 148
|
缓存 JavaScript 安全
nodejs里面的http模块介绍和使用
综上所述,Node.js的http模块是构建Web服务的基础,其灵活性和强大功能,结合Node.js异步非阻塞的特点,为现代Web应用开发提供了坚实的基础。
628 62
|
JavaScript
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)(下)
Node.js【GET/POST请求、http模块、路由、创建客户端、作为中间层、文件系统模块】(二)-全面详解(学习总结---从入门到深化)
432 0
|
JSON API 数据格式
Python网络编程:HTTP请求(requests模块)
在现代编程中,HTTP请求几乎无处不在。无论是数据抓取、API调用还是与远程服务器进行交互,HTTP请求都是不可或缺的一部分。在Python中,requests模块被广泛认为是发送HTTP请求的最简便和强大的工具之一。本文将详细介绍requests模块的功能,并通过一个综合示例展示其应用。
567 11
|
缓存 应用服务中间件 nginx
安装nginx-http-flv-module模块
本文介绍如何为Nginx安装`nginx-http-flv-module`模块。此模块基于`nginx-rtmp-module`二次开发,不仅具备原模块的所有功能,还支持HTTP-FLV播放、GOP缓存、虚拟主机等功能。安装步骤包括:确认Nginx版本、下载相应版本的Nginx与模块源码、重新编译Nginx并加入新模块、验证模块安装成功。特别注意,此模块已包含`nginx-rtmp-module`功能,无需重复编译安装。
1701 3
|
JSON API 开发者
深入解析Python网络编程与Web开发:urllib、requests和http模块的功能、用法及在构建现代网络应用中的关键作用
深入解析Python网络编程与Web开发:urllib、requests和http模块的功能、用法及在构建现代网络应用中的关键作用
337 0
|
移动开发 网络协议 C语言
详解 httptools 模块,一个 HTTP 解析器
详解 httptools 模块,一个 HTTP 解析器
591 0

热门文章

最新文章