mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
43 lines
9.8 KiB
HTML
43 lines
9.8 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Routing and runtime macros for Actix Web."><title>actix_web_codegen - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="actix_web_codegen" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-df360f571f6edeae.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../actix_web_codegen/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../actix_web_codegen/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../actix_web_codegen/index.html">actix_web_codegen</a><span class="version">4.2.2</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#attributes">Attribute Macros</a></li></ul></section></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">actix_web_codegen</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><a class="src" href="../src/actix_web_codegen/lib.rs.html#1-242">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Routing and runtime macros for Actix Web.</p>
|
||
<h2 id="actix-web-re-exports"><a class="doc-anchor" href="#actix-web-re-exports">§</a>Actix Web Re-exports</h2>
|
||
<p>Actix Web re-exports a version of this crate in it’s entirety so you usually don’t have to
|
||
specify a dependency on this crate explicitly. Sometimes, however, updates are made to this
|
||
crate before the actix-web dependency is updated. Therefore, code examples here will show
|
||
explicit imports. Check the latest <a href="https://docs.rs/actix-web/latest/actix_web/#attributes">actix-web attributes docs</a> to see which macros
|
||
are re-exported.</p>
|
||
<h2 id="runtime-setup"><a class="doc-anchor" href="#runtime-setup">§</a>Runtime Setup</h2>
|
||
<p>Used for setting up the actix async runtime. See <a href="attr.main.html" title="attr actix_web_codegen::main">main</a> macro docs.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[actix_web_codegen::main] </span><span class="comment">// or `#[actix_web::main]` in Actix Web apps
|
||
</span><span class="kw">async fn </span>main() {
|
||
<span class="kw">async </span>{ <span class="macro">println!</span>(<span class="string">"Hello world"</span>); }.<span class="kw">await
|
||
</span>}</code></pre></div>
|
||
<h2 id="single-method-handler"><a class="doc-anchor" href="#single-method-handler">§</a>Single Method Handler</h2>
|
||
<p>There is a macro to set up a handler for each of the most common HTTP methods that also define
|
||
additional guards and route-specific middleware.</p>
|
||
<p>See docs for: <a href="attr.get.html" title="attr actix_web_codegen::get">GET</a>, <a href="attr.post.html" title="attr actix_web_codegen::post">POST</a>, <a href="attr.patch.html" title="attr actix_web_codegen::patch">PATCH</a>, <a href="attr.put.html" title="attr actix_web_codegen::put">PUT</a>, <a href="attr.delete.html" title="attr actix_web_codegen::delete">DELETE</a>, <a href="attr.head.html" title="attr actix_web_codegen::head">HEAD</a>, <a href="macro@macro@connect">CONNECT</a>, <a href="attr.options.html" title="attr actix_web_codegen::options">OPTIONS</a>, <a href="attr.trace.html" title="attr actix_web_codegen::trace">TRACE</a></p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[get(<span class="string">"/test"</span>)]
|
||
</span><span class="kw">async fn </span>get_handler() -> HttpResponse {
|
||
HttpResponse::Ok().finish()
|
||
}</code></pre></div>
|
||
<h2 id="multiple-method-handlers"><a class="doc-anchor" href="#multiple-method-handlers">§</a>Multiple Method Handlers</h2>
|
||
<p>Similar to the single method handler macro but takes one or more arguments for the HTTP methods
|
||
it should respond to. See <a href="attr.route.html" title="attr actix_web_codegen::route">route</a> macro docs.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[route(<span class="string">"/test"</span>, method = <span class="string">"GET"</span>, method = <span class="string">"HEAD"</span>)]
|
||
</span><span class="kw">async fn </span>get_and_head_handler() -> HttpResponse {
|
||
HttpResponse::Ok().finish()
|
||
}</code></pre></div>
|
||
<h2 id="multiple-path-handlers"><a class="doc-anchor" href="#multiple-path-handlers">§</a>Multiple Path Handlers</h2>
|
||
<p>Acts as a wrapper for multiple single method handler macros. It takes no arguments and
|
||
delegates those to the macros for the individual methods. See <a href="attr.routes.html" title="attr actix_web_codegen::routes">routes</a> macro docs.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[routes]
|
||
#[get(<span class="string">"/test"</span>)]
|
||
#[get(<span class="string">"/test2"</span>)]
|
||
#[delete(<span class="string">"/test"</span>)]
|
||
</span><span class="kw">async fn </span>example() -> HttpResponse {
|
||
HttpResponse::Ok().finish()
|
||
}</code></pre></div>
|
||
</div></details><h2 id="attributes" class="section-header">Attribute Macros<a href="#attributes" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="attr" href="attr.connect.html" title="attr actix_web_codegen::connect">connect</a></div><div class="desc docblock-short">Creates route handler with <code>actix_web::guard::Connect</code>.</div></li><li><div class="item-name"><a class="attr" href="attr.delete.html" title="attr actix_web_codegen::delete">delete</a></div><div class="desc docblock-short">Creates route handler with <code>actix_web::guard::Delete</code>.</div></li><li><div class="item-name"><a class="attr" href="attr.get.html" title="attr actix_web_codegen::get">get</a></div><div class="desc docblock-short">Creates route handler with <code>actix_web::guard::Get</code>.</div></li><li><div class="item-name"><a class="attr" href="attr.head.html" title="attr actix_web_codegen::head">head</a></div><div class="desc docblock-short">Creates route handler with <code>actix_web::guard::Head</code>.</div></li><li><div class="item-name"><a class="attr" href="attr.main.html" title="attr actix_web_codegen::main">main</a></div><div class="desc docblock-short">Marks async main function as the Actix Web system entry-point.</div></li><li><div class="item-name"><a class="attr" href="attr.options.html" title="attr actix_web_codegen::options">options</a></div><div class="desc docblock-short">Creates route handler with <code>actix_web::guard::Options</code>.</div></li><li><div class="item-name"><a class="attr" href="attr.patch.html" title="attr actix_web_codegen::patch">patch</a></div><div class="desc docblock-short">Creates route handler with <code>actix_web::guard::Patch</code>.</div></li><li><div class="item-name"><a class="attr" href="attr.post.html" title="attr actix_web_codegen::post">post</a></div><div class="desc docblock-short">Creates route handler with <code>actix_web::guard::Post</code>.</div></li><li><div class="item-name"><a class="attr" href="attr.put.html" title="attr actix_web_codegen::put">put</a></div><div class="desc docblock-short">Creates route handler with <code>actix_web::guard::Put</code>.</div></li><li><div class="item-name"><a class="attr" href="attr.route.html" title="attr actix_web_codegen::route">route</a></div><div class="desc docblock-short">Creates resource handler, allowing multiple HTTP method guards.</div></li><li><div class="item-name"><a class="attr" href="attr.routes.html" title="attr actix_web_codegen::routes">routes</a></div><div class="desc docblock-short">Creates resource handler, allowing multiple HTTP methods and paths.</div></li><li><div class="item-name"><a class="attr" href="attr.test.html" title="attr actix_web_codegen::test">test</a></div><div class="desc docblock-short">Marks async test functions to use the Actix Web system entry-point.</div></li><li><div class="item-name"><a class="attr" href="attr.trace.html" title="attr actix_web_codegen::trace">trace</a></div><div class="desc docblock-short">Creates route handler with <code>actix_web::guard::Trace</code>.</div></li></ul></section></div></main></body></html> |