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
  • Usage
  • Getting Current Level in the Call Hierarchy
  1. Guides
  2. Network

Internal Self Calls

Introduction

Starcounter provides an efficient way for REST communication within the codehost instance. Simply put, Self is used to call handlers that are registered using the Handle class inside the codehost. To communicate between different codehosts, Http should be used. Self communication does not use either networking or shared memory, so it is very efficient. It is represented by the Self class, which is similar to the Http interface. For example, the same HTTP methods are supported, as in Http. However, in comparison, Self calls are always synchronous, so asynchronous mode is not presented in it. Like for Http, the Response object is returned as a result of Self call. To conclude, Self is used ubiquitously in Starcounter as it is the core REST communication mechanism.

Usage

Here are some examples of Self calls:

Response resp = Self.GET("/MyHandler");

Templated Self can be used to specify what object type is expected in Body of the Response and gets it as a return value, for example:

Json json = Self.GET<Json>("/MyApp/MyJsonObject/13235");

Here, an object of type Json is expected to be in the Body.

A specific JSON type can also be used:

Master master = Self.GET<Master>("/emails");

Here is an example of expecting and obtaining the string Body:

String myText = Self.GET<String>("/MyApp/MyTextDocument/54664");

or expecting a binary body:

Byte[] myBinaryData = Self.GET<Byte[]>("/EncodedDocument/34563");

Note that if the actual response Body object returned in handler is of different type than expected - the conversion exception will be thrown.

Getting Current Level in the Call Hierarchy

The hierarchy of Self calls can be quite deep and sometimes its needed to get the current call level. To achieve that there is a special thread static variable Handle.CallLevel. Every Self call the variable is incremented and then restored to current value on the way back.

PreviousHTTPNextMiddleware

Last updated 7 years ago