Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add doc for headers #147

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions docs/getting_started/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,36 @@ schema
}

type Query {
# Specify the http path for the users query
users: [User] @http(path: "/users")

# Specify the http path for the users query

users: [User] @http(path: "/users")
}

# Create a user type with the fields returned by the users api

type User {
id: Int!
name: String!
username: String!
email: String!

# Extend the user type with the posts field
# Use the current user's id to construct the path
posts: [Post] @http(path: "/users/{{value.id}}/posts")
id: Int!
name: String!
username: String!
email: String!

# Extend the user type with the posts field

# Use the current user's id to construct the path

posts: [Post] @http(path: "/users/{{value.id}}/posts")
}

# Create a post type with the fields returned by the posts api

type Post {
id: Int!
title: String!
body: String!
id: Int!
title: String!
body: String!
}
```

````

</TabItem>
<TabItem value="yml" label="yml">
Expand Down Expand Up @@ -109,7 +116,7 @@ types:
required: true
website:
type: String
```
````

</TabItem>
<TabItem value="json" label="json">
Expand Down
6 changes: 5 additions & 1 deletion docs/getting_started/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import Version from "../../src/components/Version"
import InstallCommand from "../../src/components/install"

<>
You can install the latest version - <b><Version /></b>, by using<b> NPM</b>.
You can install the latest version -{" "}
<b>
<Version />
</b>
, by using<b> NPM</b>.
</>
## NPM

Expand Down
8 changes: 4 additions & 4 deletions docs/guides/http-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ This configuration instructs Tailcall to cache responses from the designated ups

### Cache-Control headers in responses

Enabling the `cacheControlHeader` setting in Tailcall ensures that [Cache-Control] headers are included in the responses returned to clients. When activated, Tailcall dynamically sets the `max-age` directive in the `Cache-Control` header to the minimum `max-age` value encountered in any of the responses from upstream services. This approach guarantees that the caching duration for the composite response is conservative, aligning with the shortest cache validity period provided by the upstream services. By default, this feature is disabled (`false`), meaning Tailcall will not modify or add `Cache-Control` headers unless explicitly instructed to do so. This setting is distinct from the general HTTP cache setting, which controls whether responses are cached internally by Tailcall; `cacheControlHeader` specifically controls the caching instructions sent to clients.
Enabling the `cacheControl` setting in Tailcall ensures that [Cache-Control] headers are included in the responses returned to clients. When activated, Tailcall dynamically sets the `max-age` directive in the `Cache-Control` header to the minimum `max-age` value encountered in any of the responses from upstream services. This approach guarantees that the caching duration for the composite response is conservative, aligning with the shortest cache validity period provided by the upstream services. By default, this feature is disabled (`false`), meaning Tailcall will not modify or add `Cache-Control` headers unless explicitly instructed to do so. This setting is distinct from the general HTTP cache setting, which controls whether responses are cached internally by Tailcall; `cacheControl` specifically controls the caching instructions sent to clients.

Here is how you can enable the `cacheControlHeader` setting within your Tailcall schema to apply these caching instructions:
Here is how you can enable the `cacheControl` setting within your Tailcall schema to apply these caching instructions:

```graphql
schema @server(cacheControlHeader: true) {
schema @server(headers: {cacheControl: true}) {
query: Query
mutation: Mutation
}
Expand All @@ -47,7 +47,7 @@ schema @server(cacheControlHeader: true) {

### Best Practices for Enhancing REST API Performance with Tailcall

The combination of `httpCache` and `cacheControlHeader` provides a comprehensive caching solution. While `httpCache` focuses on internal caching to reduce the impact of high latency and frequent requests, `cacheControlHeader` manages client-side caching policies, ensuring an optimal balance between performance, data freshness, and efficient resource use.
The combination of `httpCache` and `cacheControl` provides a comprehensive caching solution. While `httpCache` focuses on internal caching to reduce the impact of high latency and frequent requests, `cacheControl` manages client-side caching policies, ensuring an optimal balance between performance, data freshness, and efficient resource use.

These caching primitives are beneficial for REST APIs that are latency-sensitive, have a high rate of request repetition, or come with explicit caching headers indicating cacheable responses. Together, they tackle the common challenges of optimizing REST API performance by minimizing unnecessary network traffic and server load while ensuring response accuracy.

Expand Down
10 changes: 7 additions & 3 deletions docs/operators/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ This example sets the `port` to `8090`, making Tailcall accessible at `http://lo
Always choose non-standard ports, avoiding typical ones like 80 or 8080. Make sure your chosen port is free.
:::

## cacheControlHeader
## headers

Activating the `cacheControlHeader` configuration directs Tailcall to send [Cache-Control] headers in its responses. The `max-age` value in the header matches the smallest of the values in the responses Tailcall receives from upstream services. By default, this is `false`, which means Tailcall does not set any header.
Allows intelligent configuration of the final response headers that's produced by Tailcall.

### cacheControl

Activating the `cacheControl` configuration directs Tailcall to send [Cache-Control] headers in its responses. The `max-age` value in the header matches the smallest of the values in the responses Tailcall receives from upstream services. By default, this is `false`, which means Tailcall does not set any header.

[cache-control]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control

```graphql showLineNumbers
schema @server(cacheControlHeader: true) {
schema @server(headers: {cacheControl: true}) {
query: Query
mutation: Mutation
}
Expand Down
5 changes: 3 additions & 2 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,9 @@ aside.theme-doc-sidebar-container {
width: 100%;
}

pre code, code {
font-family: var(--ifm-font-family-monospace) !important;
pre code,
code {
font-family: var(--ifm-font-family-monospace) !important;
}

nav.menu {
Expand Down
Loading