Returning a response | laravel-sitemap-rust | Spatie       

 SPATIE  

laravel-sitemap-rust
====================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-sitemap-rust](https://spatie.be/docs/laravel-sitemap-rust/v1)  Creating-sitemaps  Returning a response

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-sitemap-rust/v1) 

  Returning a response    
- [ Introduction ](https://spatie.be/docs/laravel-sitemap-rust/v1/introduction)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-sitemap-rust/v1/installation-setup)
- [ Support us ](https://spatie.be/docs/laravel-sitemap-rust/v1/support-us)
- [ Changelog ](https://spatie.be/docs/laravel-sitemap-rust/v1/changelog)
- [ Questions and issues ](https://spatie.be/docs/laravel-sitemap-rust/v1/questions-issues)
- [ Testing ](https://spatie.be/docs/laravel-sitemap-rust/v1/testing)
- [ About us ](https://spatie.be/docs/laravel-sitemap-rust/v1/about-us)

Creating sitemaps
-----------------

- [ Generating a sitemap ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/generating-a-sitemap)
- [ Manually creating a sitemap ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/manually-creating-a-sitemap)
- [ Creating a sitemap index ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/creating-a-sitemap-index)
- [ Splitting large sitemaps ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/splitting-large-sitemaps)
- [ Grouping URLs into multiple sitemaps ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/grouping-urls-into-multiple-sitemaps)
- [ Adding an XSL stylesheet ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/adding-an-xsl-stylesheet)
- [ Returning a response ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/returning-a-response)
- [ Sorting URLs ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/sorting-urls)

Customizing the crawler
-----------------------

- [ Crawl profiles ](https://spatie.be/docs/laravel-sitemap-rust/v1/customizing-the-crawler/crawl-profiles)
- [ Filtering URLs ](https://spatie.be/docs/laravel-sitemap-rust/v1/customizing-the-crawler/filtering-urls)
- [ Configuring the crawler ](https://spatie.be/docs/laravel-sitemap-rust/v1/customizing-the-crawler/configuring-the-crawler)

Adding content to URLs
----------------------

- [ Alternates ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/alternates)
- [ Images ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/images)
- [ Videos ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/videos)
- [ News ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/news)
- [ Sitemapable models ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/sitemapable-models)

Advanced usage
--------------

- [ Scheduled generation ](https://spatie.be/docs/laravel-sitemap-rust/v1/advanced-usage/scheduled-generation)
- [ Writing to disks ](https://spatie.be/docs/laravel-sitemap-rust/v1/advanced-usage/writing-to-disks)
- [ Handling errors ](https://spatie.be/docs/laravel-sitemap-rust/v1/advanced-usage/handling-errors)

 Returning a response
====================

- `Sitemap` and `SitemapIndex` implement Laravel's `http::IntoResponse`.
- Return an owned document directly from an async handler:

```
use laravel::Application;
use spatie_sitemap::{Sitemap, SitemapIndex};

async fn pages() -> laravel::Result<Sitemap> {
    let mut sitemap = Sitemap::new("https://example.com")?;
    sitemap.add("/page1").add("/page2");
    Ok(sitemap)
}

async fn index() -> laravel::Result<SitemapIndex> {
    let mut index = SitemapIndex::new("https://example.com")?;
    index.add("/sitemap.xml");
    Ok(index)
}

let app = Application::configure()
    .with_routing(|routing, _| {
        routing.web(|route| {
            route.get("/sitemap.xml", pages);
            route.get("/sitemap_index.xml", index);
        });
    })
    .create();
```

Successful documents return status 200 and `text/xml` with the rendered XML bytes. Rendering errors become Laravel error responses rather than malformed XML with status 200. `to_response()` is also available when you need a fallible conversion before returning the document.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
