HTTP integration | laravel-feed-rust | Spatie       

 SPATIE  

laravel-feed-rust
=================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-feed-rust](https://spatie.be/docs/laravel-feed-rust/v1)  HTTP integration

 Version   v1      

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

  HTTP integration    
- [ Introduction ](https://spatie.be/docs/laravel-feed-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-feed-rust/v1/support-us)
- [ Installation ](https://spatie.be/docs/laravel-feed-rust/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-feed-rust/v1/usage)
- [ HTTP integration ](https://spatie.be/docs/laravel-feed-rust/v1/http)
- [ Customization ](https://spatie.be/docs/laravel-feed-rust/v1/customization)
- [ Changelog ](https://spatie.be/docs/laravel-feed-rust/v1/changelog)
- [ Testing ](https://spatie.be/docs/laravel-feed-rust/v1/testing)

 HTTP integration
================

###  On this page 

1. [ Publication feeds ](#content-publication-feeds)

- Register feeds on the native `Router` in the application's web middleware group.
- The async loader runs once per GET or HEAD request. It returns `laravel::Result<Vec<T>>`, where `T` implements `Feedable`.

This self-contained example creates an application and sends a request through its real router and middleware:

```
use laravel::{Application, config::Env, testing::MakesHttpRequests};
use spatie_feed::{Feed, FeedItem, register_feed};

async fn posts() -> laravel::Result<Vec<FeedItem>> {
    Ok(vec![FeedItem::new(
        42, "A post", "2026-11-30T12:00:00+01:00[Europe/Brussels]".parse().map_err(|error| laravel::Error::new(500, error))?,
        "/42-a-post", "<p>The complete post.</p>", "Freek Van der Herten",
    ).author_email("freek@spatie.be")])
}

let feed = Feed::new("My blog", "https://example.com/feed")?
    .description("All posts")
    .language("en-US");

let app = Application::configure()
    // This example uses an isolated test environment. Real applications use their own config.
    .replace_env(Env::from_iter([
        ("APP_KEY", "01234567890123456789012345678901"),
        ("APP_ENV", "testing"),
        ("SESSION_DRIVER", "memory"),
    ]))
    .with_routing(move |routing, _| {
        routing.web(move |router| {
            register_feed(router, "/feed", feed, posts);
        });
    })
    .create();

app.get("/feed").await
    .assert_ok()
    .assert_header("content-type", "application/xml;charset=UTF-8")
    .assert_see("https://example.com/42");
```

- Repeat registration for each feed with its own metadata, self URL and loader.
- Capture a clonable repository in a loader, or use the native request context.
- Loader errors retain their framework status. Rendering errors become HTTP 500 responses, not empty successful feeds.
- `register_feed` returns `&mut Route` for native middleware configuration.
- Use `router.prefix("/syndication").group(|router| { ... })` for a shared prefix. Each feed's absolute self URL must include the prefix.
- Error-only loaders need an explicit item type, such as `Err::<Vec<FeedItem>, _>(error)`.
- For request extractors, use a normal async handler on `router.get` and return `feed.items(entries).to_response().map_err(|error| laravel::Error::new(500, error))`.

Publication feeds
-----------------------------------------------------------------------------------------------------------

- Select published posts, apply your filters, choose ordering and limit results in the loader. Rendering does not query or filter entries.
- Use a stable entry ID, canonical link and publication timestamp. Supply full rendered HTML with any application-specific transformations already applied.
- Add response caching in application middleware when needed. The package does not cache or share loaded entries between requests.

 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)
