This articlemay rely excessively on sourcestoo closely associated with the subject, potentially preventing the article from beingverifiable andneutral. Please helpimprove it by replacing them with more appropriatecitations toreliable, independent sources.(December 2023) (Learn how and when to remove this message) |
| Rocket | |
|---|---|
| Developer | Sergio Benitez[1] |
| Initial release | 2016; 10 years ago (2016) |
| Stable release | |
| Written in | Rust |
| Operating system | Linux,macOS,Windows,FreeBSD,OpenBSD |
| Type | Web framework |
| License | MIT License orApache License |
| Website | rocket |
| Repository | github |
Rocket is aweb framework written inRust.[3][4] It supports handlingHTTP requests,Web Sockets,JSON,templating, and more. Its design was inspired byRails,Flask, Bottle, andYesod.[5] It isdually licensed under theMIT License and theApache License.
To create a web server with Rocket, the user will define an application, then use the "mount" function to attach "routes" to it. Each "route" is a rust function with amacro attached to it. The function will define code that should respond to anHTTP request. The macro that is written as part of the function declaration will define whichHTTP Method (such as GET, POST, PUT, etc.) it should be handle, as well as a pattern describing theURL it should be relevant to.
This is an example of a working rocket application:
#[macro_use]externcraterocket;#[get("/hello/<name>/<age>")]fnhello(name:&str,age:u8)->String{format!("Hello, {} year old named {}!",age,name)}#[launch]fnrocket()->_{rocket::build().mount("/",routes![hello])}
Sending an HTTP GET request to/hello/John/50 would return the following response:
Hello, 50 year old named John!.
Rocket implements the following features:
/hello route with "Hello World":#[get("/")]fnindex()->&'staticstr{"Hello, world!"}
Thiscomputer-library-related article is astub. You can help Wikipedia byadding missing information. |