Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Rocket (web framework)

From Wikipedia, the free encyclopedia
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
DeveloperSergio Benitez[1]
Initial release2016; 10 years ago (2016)
Stable release
0.5.1[2] Edit this on Wikidata / 23 May 2024; 20 months ago (23 May 2024)
Written inRust
Operating systemLinux,macOS,Windows,FreeBSD,OpenBSD
TypeWeb framework
LicenseMIT License orApache License
Websiterocket.rs
Repositorygithub.com/rwf2/Rocket

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.

Example

[edit]

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!.

Features

[edit]

Rocket implements the following features:

  • Routing - Rocket allows the user to define the structure of routes that the application should consider, as well as the code that should run in different routing combination. For example, the following code will make the rocket application to respond to the/hello route with "Hello World":
    #[get("/")]fnindex()->&'staticstr{"Hello, world!"}
  • Form Data - Rocket allows the user to define aSerde model, and use it to parse the Form Data, and pass it as native rust object to the route handler.
  • Request Guards - the route handlers can contain a special kind of parameters named "Request Guard"s that are meant to prevent the code inside the handler to be called in case a certain condition is not met. This feature can be used for example, to prevent requests that do not contain aAPI Key. By using the Request Guard feature, the user can define the condition in one place, and apply it to prevent access to multiple routes by adding the guard to their list of parameters.

References

[edit]
  1. ^"Sergio Benitez - Who Am I?".sergio.bz. Retrieved2020-05-30.
  2. ^"Release 0.5.1". 23 May 2024. Retrieved25 May 2024.
  3. ^Schlothauer, Sarah (December 14, 2018)."Speedy Rust framework for web apps burns through the sky".JAXenter. RetrievedMay 29, 2020.
  4. ^Ekwuno, Obinna (October 18, 2019)."The best Rust frameworks to check out in 2019".LogRocket. RetrievedMay 29, 2020.
  5. ^"Introduction - Rocket Programming Guide".rocket.rs. Retrieved2020-05-30.

External links

[edit]
.NET
C++
ColdFusion
Common Lisp
Haskell
Java
JavaScript
Back end
Server-side
Full-stack
Front end
Client-side
Perl
PHP
Python
Ruby
Rust
Scala
Smalltalk
Other languages


Stub icon

Thiscomputer-library-related article is astub. You can help Wikipedia byadding missing information.

Retrieved from "https://en.wikipedia.org/w/index.php?title=Rocket_(web_framework)&oldid=1331547086"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp