Starcounter
HomeDownloadDocsCommunity
2.3.1
2.3.1
  • Starcounter Documentation
  • Getting Started
  • Starcounter
    • Collapsing the Stack
      • Complexity and Scalability Tradeoff
      • The Future of Micro-Services
      • 10 Benefits of Collapsing the Stack
    • Integrated Database and Web Server
  • Hello World - Tutorial
    • Create a Database Class
    • Create a Real Time UI
    • First Interactive UI
    • Computed Properties
    • Expense Tracker
    • Cancel and Delete
    • The Next Step
  • Guides
    • Database
      • Database Classes
      • Data manipulation
      • Object Identity and Object References
      • Querying with SQL
      • Data Types
      • Relations
      • Inheritance
      • Sharing data
      • Database Configuration
      • Comparing Database Objects
      • Referential Integrity and Constraints
    • SQL
      • Identifiers
      • Path Expressions
      • Data operators
      • Joins
      • Aggregates
      • Comparisons and Logical Operators
      • Sorting
      • Fetch
      • Offset Key
      • Indexes
      • Literals
      • Query Plan Hints
      • Reserved words
      • Query for Database Classes
      • SQL Isolation Between Applications
    • Transactions
      • Short-Running Transactions
      • Long running transactions
      • Using Transactions
      • Running Background Jobs
      • Commit Hooks
    • Typed JSON
      • JSON-by-example
      • Code-Behind
      • Data Bindings
      • Callback Methods
      • Responding with JSON
      • Accepting JSON in Requests
      • Primitive Arrays and Single Value Types
      • Typed JSON Internals
    • Blendable Web Apps
      • Starcounter MVVM
      • Palindrom
      • Client-Side Stack
      • Sessions
      • HTML Views
      • App Shell
      • Web Components
      • View Attaching
      • View Composing
      • HTML Compositions
      • HTML Views Blending Guidelines
      • Avoiding CSS conflicts
      • Debugging
    • Network
      • HTTP
      • Internal Self Calls
      • Middleware
      • Anonymous or Substitute Handlers
      • URL Aliases and Redirects
      • Network Gateway
      • Static File Server
      • External HTTP Calls
      • WebSocket
      • Avoiding URI conflicts
      • TCP Sockets
      • UDP Sockets
    • Publishing Apps
    • Working with Starcounter
      • Release Channels
      • Starting and Stopping Apps
      • Administrator Web UI
      • Star CLI
      • StarAdmin CLI
      • StarDump CLI
      • Working in Visual Studio
      • Error Log
      • Using HTTPS on NGINX
      • Using HTTPS on IIS
      • Run Starcounter in Production
      • Weaver
      • Investigating App Crashes
      • Configuration Structure
      • Database Refactoring
      • Using Unload/Reload to Modify Database Schema
      • Kernel Questions and Answers
      • Log Files
  • Cookbook
    • Attach an HTTP Request to an Existing Long-Running Transaction
    • Cookie-Based Authentication
    • Timestamp on Object Creation
    • Creating Strongly Typed JSON Collections
    • Migrating From 2.2 to 2.3+
    • Multiple Pages
    • Icons
    • Proposed Project Structure
    • Acceptance Testing with Selenium
    • Requesting a User to Authenticate
    • How to delete unused tables and columns
Powered by GitBook
On this page
  • Introduction
  • Things to Know About Anonymous Handlers
  • When to Use Anonymous Handlers
  • Shared UI Sections
  • UI View Composition with Layout Editor
  1. Guides
  2. Network

Anonymous or Substitute Handlers

Introduction

Sometimes, it is required to get a partial without declaring a handler. This is when anonymous handlers became handy.

model.Partial = Self.GET("/custom-url", () =>
{
    return new Page()
    {
        Html = "/custom-page.html"
    };
});

The model.Partial will contain the returned new Page() and all the responses from all the apps mapped to the "/custom-url". The anonymous handler can be called to any url.

Things to Know About Anonymous Handlers

  • The anonymous handlers should never be used for direct calls to handlers defined in other apps. Follow the practice that the apps should not be aware of each other.

  • An app can only have one response per URL, that is why anonymous handlers can't be combined with declared ones.

  • The Html property is not required, it may be blank if the calling app does not have any response.

  • The anonymous handler response should be of type Starcounter.Page otherwise it won't be possible to merge with other responses.

When to Use Anonymous Handlers

Shared UI Sections

The most common case is the Launcher. The Launcher defines different UI sections and populates them with anonymous Self.GET requests.

//UriMapping.MappingUriPrefix - a constant, equals to "/sc/mapping"
model.Menu = Self.GET(UriMapping.MappingUriPrefix + "/menu", () => new Page());

The model.Menu contains merged responses from all handlers mapped to /sc/mapping/menu. The mapping would look like this:

UriMapping.Map("/Products/menu", UriMapping.MappingUriPrefix + "/menu");

Read more about mapping here: Mixing apps.

UI View Composition with Layout Editor

Composition technology requires some extra HTML elements and JSON wrapping which are injected per partial using middleware. This means that partials which are created without a request won't be available for view composition.

// The IndexPage is available for view composition.
// It is retrieved with a request.
Handle.GET("/my-app", () => new IndexPage());
Handle.GET("/my-app", () => new MasterPage()
{
    // The IndexPage is not available for view composition.
    // It is retrieved without a request.
    CurrentPage = new IndexPage()
});
// The MasterPage and the IndexPage are both retrieved
// with a request and available for view composition.
Handle.GET("/my-app", () => MasterPage()
{
    CurrentPage = Self.GET("/my-app/partials/index")
});

Handle.GET("/my-app/partials/index", () => new IndexPage());

An anonymous handler can be used instead of the custom partial handler definition.

// The IndexPage is still available for view composition,
// It is retrieved with an anonymous request.
Handle.GET("/my-app", () => MasterPage()
{
    CurrentPage = Self.GET("/my-app/partials", () => new IndexPage())
});
PreviousMiddlewareNextURL Aliases and Redirects

Last updated 7 years ago