Rocket (web Framework)
   HOME

TheInfoList



OR:

Rocket is a
web framework A web framework (WF) or web application framework (WAF) is a software framework that is designed to support the development of web applications including web services, web resources, and web APIs. Web frameworks provide a standard way to build a ...
written in
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH) ...
. It supports handling
HTTP requests HTTP (Hypertext Transfer Protocol) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, wher ...
, Web Sockets,
JSON JSON (JavaScript Object Notation, pronounced or ) is an open standard file format and electronic data interchange, data interchange format that uses Human-readable medium and data, human-readable text to store and transmit data objects consi ...
, templating, and more. Its design was inspired by
Rails Rail or rails may refer to: Rail transport *Rail transport and related matters * Railway track or railway lines, the running surface of a railway Arts and media Film * ''Rails'' (film), a 1929 Italian film by Mario Camerini * ''Rail'' (1967 fi ...
,
Flask Flask may refer to: Container * Hip flask, a small container used to carry liquid * Laboratory flask, laboratory glassware for holding larger volumes than simple test tubes ** Erlenmeyer flask, a common laboratory flask with a flat bottom, a c ...
, Bottle, and
Yesod Yesod (Hebrew: יְסוֹד ''Yəsōḏ'', Tiberian: ''Yăsōḏ'', "foundation") is a sephirah or node in the kabbalistic Tree of Life, a system of Jewish philosophy. Yesod, located near the base of the Tree, is the sephirah below Hod and ...
. It is dually licensed under the
MIT License The MIT License is a permissive software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts very few restrictions on reuse and therefore has high license compatibility. Unl ...
and the
Apache License The Apache License is a permissive free software license written by the Apache Software Foundation (ASF). It allows users to use the software for any purpose, to distribute it, to modify it, and to distribute modified versions of the software ...
. 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 a macro attached to it. The function will define code that should respond to an
HTTP request HTTP (Hypertext Transfer Protocol) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, wher ...
. The macro that is written as part of the function declaration will define which
HTTP Method HTTP (Hypertext Transfer Protocol) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, wher ...
(such as GET, POST, PUT, etc.) it should be handle, as well as a pattern describing the
URL A uniform resource locator (URL), colloquially known as an address on the Web, is a reference to a resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identi ...
it should be relevant to.


Example

This is an example of a working rocket application: # acro_useextern crate rocket; # /")">et("/hello//")fn hello(name: &str, age: u8) -> String # aunchfn rocket() -> _ Sending an HTTP GET request to /hello/John/20 would return the following response: Hello, 20 year old named John!.


Features

Rocket implements the following features: *
Routing Routing is the process of selecting a path for traffic in a Network theory, network or between or across multiple networks. Broadly, routing is performed in many types of networks, including circuit-switched networks, such as the public switched ...
- 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": # et("/")fn index() -> &'static str * Form Data - Rocket allows the user to define a Serde 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 a
API Key An application programming interface (API) key is a secret unique identifier used to authenticate and authorize a user, developer, or calling program to an API. Cloud computing providers such as Google Cloud Platform and Amazon Web Services reco ...
. 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


External links

* * Web frameworks Free software programmed in Rust Software using the Apache license {{Compu-library-stub