|
1 | 1 | ---
|
2 |
| -title: Hosts and the Loader |
| 2 | +title: Hosts and the loader |
3 | 3 | menuPosition: 4
|
4 | 4 | ---
|
5 | 5 |
|
6 |
| -## NOT YET WRITTEN |
| 6 | +The **Fluid loader** is one of the key parts of the Fluid Framework. Developers use the Fluid loader within their |
| 7 | +applications to load Fluid containers and to initiate communication with the Fluid service. |
| 8 | + |
| 9 | +A **Fluid host** is any application that uses the Fluid loader to load a Fluid container. |
| 10 | + |
| 11 | +The Fluid loader uses a plugin model. |
| 12 | + |
| 13 | + |
| 14 | +## Who needs a Fluid loader? |
| 15 | + |
| 16 | +If your app or website will load a Fluid container, then you are creating a Fluid host and you will need to use the |
| 17 | +Fluid loader! |
| 18 | + |
| 19 | +If you are building a Fluid container and you will not build a standalone application with Fluid, you may still be |
| 20 | +interested in learning about the Fluid loader. The Fluid loader includes capabilities, such as host scopes, that are used |
| 21 | +by containers. |
| 22 | + |
| 23 | +You may also want to host your Fluid container on a standalone website. |
| 24 | + |
| 25 | + |
| 26 | +## Summary |
| 27 | + |
| 28 | +The Fluid loader loads Fluid containers by connecting to the Fluid service and fetching Fluid container code. From a |
| 29 | +system architecture perspective, the Fluid loader sits in between the Fluid service and a Fluid container. |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +The Fluid loader is intended to be extremely generic. To maintain generic-ness, the loader uses a plugin model. With the |
| 34 | +right plugins (drivers, handlers, resolvers), the Fluid loader will work for any wire protocol and any service |
| 35 | +implementation. |
| 36 | + |
| 37 | +The loader mimicks existing web protocols. Similar to how the browser requests state and app logic (a website) from a |
| 38 | +web server, a Fluid host uses the loader to request a [Fluid container](./containers-runtime.md) from the Fluid service. |
| 39 | + |
| 40 | +## host responsibilities |
| 41 | + |
| 42 | +A Fluid host creates a Fluid loader with a URL resolver, Fluid service driver, and code loader. The host then requests a |
| 43 | +Fluid container from the loader. Finally, the host *does something* with the Fluid containers. A host can request |
| 44 | +multiple containers from the loader. |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +We'll talk about each of these parts, starting with the request and loader dependencies, over the next sections. |
| 49 | + |
| 50 | +## Loading a container - Class by Class |
| 51 | + |
| 52 | +Let's address the role of each part of the Fluid loader and dive in to some details. |
| 53 | + |
| 54 | +### Request |
| 55 | + |
| 56 | +The request includes a Fluid container URL and optional header information. This URL contains a protocol and other |
| 57 | +information that will be parsed by the URL Resolver to identify where the container is located. |
| 58 | + |
| 59 | +This is not part of instantiating the loader. The request kicks of the process of loading a container. |
| 60 | + |
| 61 | +### URL Resolver |
| 62 | + |
| 63 | +The URL Resolver parses a request and returns an `IFluidResolvedUrl`. This object includes all the endpoints and tokens |
| 64 | +needed by the Fluid service driver to access the container. |
| 65 | + |
| 66 | +An example IFluidResolvedUrl includes the below information. |
| 67 | + |
| 68 | +```typescript |
| 69 | +const resolvedUrl: IFluidResolvedUrl = { |
| 70 | + endpoints: { |
| 71 | + deltaStorageUrl: "www.ContosoFluidService.com/deltaStorage", |
| 72 | + ordererUrl: "www.ContosoFluidService.com/orderer" |
| 73 | + storageUrl: "www.ContosoFluidService.com/storage", |
| 74 | + }, |
| 75 | + tokens: { jwt: "token" }, |
| 76 | + type: "fluid", |
| 77 | + url: "fluid://www.ContosoFluidService.com/ContosoTenant/documentIdentifier", |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +You may notice we are mimicking the DNS and protocol lookup a browser performs when loading a webpage. That's because a |
| 82 | +loader may access containers stored on multiple Fluid services. Furthermore, each Fluid service could be operating with |
| 83 | +a different API and protocol. |
| 84 | + |
| 85 | +### Fluid service driver (DocumentServiceFactory) |
| 86 | + |
| 87 | +The loader uses a Fluid service driver to connect to a Fluid service. |
| 88 | + |
| 89 | +While many developers will only load one container at a time, it's interesting to consider how the loader handles |
| 90 | +loading two containers that are stored on different Fluid services. To keep track of the services, the loader uses the |
| 91 | +protocol from the resolved URL to identify the correct Fluid service driver for the Fluid service. |
| 92 | + |
| 93 | +### Code loader |
| 94 | + |
| 95 | +The loader uses the code loader to fetch container code. Because a Fluid container is a app logic and distributed state |
| 96 | +we need all of the connected clients to agree on the same container code. |
| 97 | + |
| 98 | +### Scopes |
| 99 | + |
| 100 | +Scopes allow the container access to resources from the host. For example, the host may have access to an authorization |
| 101 | +context that the container code is not trusted to access. The host can provide a scope to the container that federates |
| 102 | +access to the secure resource. |
| 103 | + |
| 104 | +## Handling the response |
| 105 | + |
| 106 | +The Fluid loader will return a response object from the request. This is a continuation of our web protocol metaphor, |
| 107 | +you'll receive an object with a mimeType (e.g. "fluid/object"), response status (e.g. 200), and a value (e.g. the Fluid |
| 108 | +object). |
| 109 | + |
| 110 | +The host is responsible for checking that this response is valid. Did the loader return a 200? Is the mimeType correct? |
| 111 | +As the Fluid Framework expands, we intend to make further use of these responses. |
| 112 | + |
| 113 | +The host can then use [feature detection via IFluidObject](./feature-detection-iprovide.md) to query for features and |
| 114 | +then integrate the container into the application. |
0 commit comments