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

Upgrade to Astro v3 guide #4166

Merged
merged 141 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
f399b68
initial page
sarah11918 Aug 10, 2023
1f7eeba
a few entries to get us started
sarah11918 Aug 10, 2023
ef1325c
added some more entries
sarah11918 Aug 10, 2023
a6a08e6
document Astro.cookies, compressHTML and default port
sarah11918 Aug 10, 2023
58c0d69
updates sidebar entry and adds more items to guide
sarah11918 Aug 15, 2023
d870043
update sidebar in international versions
sarah11918 Aug 15, 2023
eee3d39
Merge branch 'main' into v3-upgrade-guide
sarah11918 Aug 15, 2023
95448d0
add more entries
sarah11918 Aug 15, 2023
61a35a5
typo: fix `astro.mjs.config` to `astro.config.mjs`
ElianCodes Aug 16, 2023
edfe8a9
refactor: endpoint methods to uppercase variants
ElianCodes Aug 16, 2023
2f4983c
chore: update DEL to DELETE
ElianCodes Aug 16, 2023
9e4f559
Merge branch 'main' into v3-upgrade-guide
sarah11918 Aug 16, 2023
e149212
Merge branch 'main' into v3-upgrade-guide
sarah11918 Aug 17, 2023
09f569f
chore: remove `<Markdown />` component
ElianCodes Aug 17, 2023
1adfb57
Merge branch 'main' into v3-upgrade-guide
sarah11918 Aug 18, 2023
6b0b53d
all beta 0 and 1 placeholders entered
sarah11918 Aug 18, 2023
5c87a8e
edit JSX entry
sarah11918 Aug 18, 2023
060607b
all placeholder entries in up to date!
sarah11918 Aug 18, 2023
33252d2
added experimental flags to remove
sarah11918 Aug 19, 2023
adc2cc4
deleted the assets page since it won't be in new docs
sarah11918 Aug 19, 2023
1f8262f
Merge branch 'main' into v3-upgrade-guide
sarah11918 Aug 19, 2023
6a32051
Update CSS Bundle Control for 3.0 (#4253)
lilnasy Aug 19, 2023
0f62bd2
Use astro: namespace modules (#4239)
matthewp Aug 19, 2023
58e22a8
feat: document astro features (#3924)
ematipico Aug 19, 2023
50a5f9e
feat: document logger for Astro integrations (#3817)
ematipico Aug 19, 2023
e76b7e6
removed Assets from sidebar since file was deleted
sarah11918 Aug 19, 2023
3210dcc
updated image links to point to page we want them to visit
sarah11918 Aug 19, 2023
fb9044b
edited removed astro image integration
sarah11918 Aug 19, 2023
d53181c
edited removed markdown component
sarah11918 Aug 19, 2023
427f073
edited build config options moved to adapters
sarah11918 Aug 19, 2023
2635170
remove extra build to adapter code samples
sarah11918 Aug 19, 2023
18c5a64
updated typescript version entry
sarah11918 Aug 19, 2023
864fc6d
kebab case, astro check entries done; end of REMOVEDs
sarah11918 Aug 19, 2023
747a91c
tralingslash default behavior entry
sarah11918 Aug 19, 2023
7cb56ee
htmlcompress entry
sarah11918 Aug 19, 2023
68f7316
scopedStyleStrategy and added links up to here
sarah11918 Aug 19, 2023
0db35b1
typo in trailingSlash
sarah11918 Aug 19, 2023
736d767
scoped style link
sarah11918 Aug 19, 2023
389d6a3
inlineStyleSheets plus code example syntax fixes up to here
sarah11918 Aug 19, 2023
a0ef058
class:list entries
sarah11918 Aug 19, 2023
aab8aaa
defalt port
sarah11918 Aug 19, 2023
1717ef3
getStaticPaths flattening entry
sarah11918 Aug 19, 2023
b5bead3
internal API endpoints entry
sarah11918 Aug 19, 2023
5117ac0
squoosh sharp
sarah11918 Aug 19, 2023
aeecbc8
HTTP request methods and more links to this point
sarah11918 Aug 19, 2023
00e6123
shortened image service title
sarah11918 Aug 19, 2023
cd4ef96
astro.cookies entry
sarah11918 Aug 19, 2023
714b5cb
final draft done!!
sarah11918 Aug 19, 2023
ea80c14
feat: document adapter features (#3917)
ematipico Aug 21, 2023
e58d9d9
Update capitalisation of GET
TheOtterlord Aug 21, 2023
873d99c
Apply suggestions from EVERYONE's code review!
sarah11918 Aug 21, 2023
4d76d73
Touche, Matthew.
sarah11918 Aug 21, 2023
09309f3
Every time someone has a good idea, we commit!
sarah11918 Aug 21, 2023
2f1fdf4
Document experimental JS API (#4234)
bluwy Aug 21, 2023
20f3664
Merge branch 'main' into v3-upgrade-guide
TheOtterlord Aug 22, 2023
41b0250
Update Firebase example to use cookies.has() (#4302)
matthewp Aug 22, 2023
c50bba3
last new entries for upgrade guide! Code freeze!
sarah11918 Aug 22, 2023
17a8228
Mostly formatting catches, also build config DEPRECATED and line high…
sarah11918 Aug 22, 2023
740d821
missed a formatting correction
sarah11918 Aug 22, 2023
98f8f99
moves build config options down to deprecated section
sarah11918 Aug 22, 2023
0412b2e
bluwy nits!
sarah11918 Aug 23, 2023
b41a7ba
earlier link to image upgrade advice
sarah11918 Aug 23, 2023
e164c37
upgrade node version to 18.14.1 in English files only
sarah11918 Aug 23, 2023
f71a939
removed examples that listed astrojs/image
sarah11918 Aug 23, 2023
733571b
Merge branch 'main' into v3-upgrade-guide
TheOtterlord Aug 23, 2023
03df3a8
Generate v3 reference docs (#4327)
TheOtterlord Aug 23, 2023
76ab7f0
deleting es/guides/assets
sarah11918 Aug 23, 2023
e7706e1
deleted guides/assets from nav.ts files that had it
sarah11918 Aug 23, 2023
dea089e
remove mention of assets folder from project structure
sarah11918 Aug 23, 2023
617eff8
Update `class:list` and astro-hash classes (#4322)
natemoo-re Aug 24, 2023
c421b01
Remove markdown draft reference (#4354)
bluwy Aug 24, 2023
f86509e
Merge branch 'main' into v3-upgrade-guide
sarah11918 Aug 24, 2023
108287a
update endpoints
ElianCodes Aug 25, 2023
88d2195
update endpoints
ElianCodes Aug 25, 2023
d3af1a3
apply Blu's suggestions
ElianCodes Aug 25, 2023
641806f
Merge branch 'main' into v3-upgrade-guide
sarah11918 Aug 25, 2023
07a353e
clearer, and scarier unexperimental image assets
sarah11918 Aug 25, 2023
0297c6c
translatable
sarah11918 Aug 25, 2023
a91adb3
View transitions 3.0 changes (#4320)
matthewp Aug 25, 2023
f14d83c
remove note to Team Docs
sarah11918 Aug 25, 2023
a944b81
remove Canadian spelling
sarah11918 Aug 25, 2023
bdb2bd8
remove advice to uninstall sharp
sarah11918 Aug 25, 2023
5ac2989
Merge branch 'main' into v3-upgrade-guide
sarah11918 Aug 25, 2023
a2901e3
Fix import
yanthomasdev Aug 27, 2023
5f74391
Merge branch 'main' into v3-upgrade-guide
yanthomasdev Aug 27, 2023
796ba50
friendly note!
sarah11918 Aug 27, 2023
65dcdea
ci: update reference docs (#4361)
astrobot-houston Aug 27, 2023
18897a4
ci: update integration docs (#4362)
astrobot-houston Aug 27, 2023
458b362
add deprication note to simple objects in endpoints
ElianCodes Aug 28, 2023
316b0e7
correct endpoints examples for ResponseWithEncoding
ElianCodes Aug 28, 2023
8190f7e
backnit
yanthomasdev Aug 29, 2023
0895eaf
put the v in the 2
yanthomasdev Aug 29, 2023
333cdd5
put the v in the 3
yanthomasdev Aug 29, 2023
7b89c40
put the v in the 3 part 2
yanthomasdev Aug 29, 2023
4bb5430
wording
yanthomasdev Aug 29, 2023
c4d2499
chore: supplement `functionPerRoute` docs (#4419)
ematipico Aug 29, 2023
355b667
Add note about passing classes to children
yanthomasdev Aug 29, 2023
9a8f0a3
Add some whitespace
yanthomasdev Aug 29, 2023
449aa61
Merge branch 'main' into v3-upgrade-guide
yanthomasdev Aug 29, 2023
2973b8e
i18n(ja): Update tutorial for v3 (#4415)
morinokami Aug 30, 2023
585d2ad
i18n(es): Update `tutorial/` `V3` (#4372)
Waxer59 Aug 30, 2023
dc1c9cf
i18n(ja): Update installation guides for v3 (#4414)
morinokami Aug 30, 2023
8153981
i18n(es): Update install/v3 (#4379)
Waxer59 Aug 30, 2023
8f2b8fe
ci: update integration docs (#4400)
astrobot-houston Aug 30, 2023
695855e
i18n(es): Update `view-transitions.mdx v3` (#4370)
Waxer59 Aug 30, 2023
9e441de
i18n(pt-BR): Update remaining `reference/` pages for 3.0 (#4407)
yanthomasdev Aug 30, 2023
027540c
i18n(ja): Update integrations-guide.mdx for v3 (#4398)
morinokami Aug 30, 2023
490e92b
i18n(ja): Update vercel.mdx for v3 (#4397)
morinokami Aug 30, 2023
55098b7
i18n(ja): Update styling.mdx for v3 (#4413)
morinokami Aug 30, 2023
9ad5898
i18n(ja): Update middleware.mdx for v3 (#4412)
morinokami Aug 30, 2023
3cd09f3
i18n(es): Update `reference/` `V3` (#4409)
Waxer59 Aug 30, 2023
4a06bb0
i18n(ja): Update content-collections.mdx for v3 (#4396)
morinokami Aug 30, 2023
3a286f5
i18n(ja): Update project-structure.mdx for v3 (#4395)
morinokami Aug 30, 2023
a1b49a5
i18n(ja): Update why-astro.mdx for v3 (#4394)
morinokami Aug 30, 2023
799eb0d
i18n(es): Update `guides/` `V3` (#4383)
Waxer59 Aug 30, 2023
33687c8
i18n(es): Update guides/integrations-guide/ V3 (#4381)
Waxer59 Aug 30, 2023
8d3db5f
i18n(es): Update guides/backend/ & guides/deploy/ V3 (#4380)
Waxer59 Aug 30, 2023
852468d
i18n(es): Update recipes/ V3 (#4373)
Waxer59 Aug 30, 2023
872dd99
i18n(es): Updated `concepts/` & `core-concepts/` `V3` (#4377)
Waxer59 Aug 30, 2023
1e7ff27
i18n(pt-BR): Update `view-transitions.mdx` for 3.0 (#4392)
yanthomasdev Aug 30, 2023
5fe70e3
i18n(pt-BR): Translate `upgrade-to/v3` and update smaller 3.0 changes…
yanthomasdev Aug 30, 2023
6429039
i18n(es): Translate `v3.mdx` `V3` (#4375)
Waxer59 Aug 30, 2023
6c1375f
i18n(es): Update vercel.mdx V3 (#4423)
Waxer59 Aug 30, 2023
197ec20
Add v3 callout to getting started page
delucis Aug 30, 2023
0ecb373
i18n(es): Update `images` `V3` (#4408)
Waxer59 Aug 30, 2023
44e1d3e
i18n(zh-cn): Upgrade to Astro v3 guide for simplified Chinese (#4353)
liruifengv Aug 30, 2023
fc1881e
i18n(ja): Update view-transitions.mdx for v3 (#4424)
morinokami Aug 30, 2023
9cb7d78
[v3 image assets] (#3739)
sarah11918 Aug 30, 2023
437cc33
fix link 1
yanthomasdev Aug 30, 2023
37ac626
fix link 2
yanthomasdev Aug 30, 2023
7e61c23
fix link 3
yanthomasdev Aug 30, 2023
09653b0
Merge branch 'main' into v3-upgrade-guide
yanthomasdev Aug 30, 2023
9b1bdb5
Remove `#draft-pages` link
yanthomasdev Aug 30, 2023
de5cb1c
i18n(zh-cn): Update getting-started.mdx (#4426)
liruifengv Aug 30, 2023
c5152b8
i18n(es): update getting started (#4427)
Waxer59 Aug 30, 2023
87f605d
Update PT-BR getting-started
yanthomasdev Aug 30, 2023
43414ca
Merge branch 'main' into v3-upgrade-guide
yanthomasdev Aug 30, 2023
6eecb05
FIX ALL THEM LINKS
yanthomasdev Aug 30, 2023
3f924b7
Merge branch 'v3-upgrade-guide' of https://github.com/withastro/docs …
yanthomasdev Aug 30, 2023
52939cd
fix link to experimental option
sarah11918 Aug 30, 2023
b8081b5
FIX LINKS PLEASE
yanthomasdev Aug 30, 2023
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
34 changes: 15 additions & 19 deletions src/content/docs/en/core-concepts/endpoints.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Endpoints export a `get` function (optionally `async`) that receives a [context
```ts
// Example: src/pages/builtwith.json.ts
// Outputs: /builtwith.json
export async function get({params, request}) {
export async function GET({params, request}) {
return {
body: JSON.stringify({
name: 'Astro',
Expand All @@ -30,7 +30,7 @@ export async function get({params, request}) {
The return object can also have an `encoding` property. It can be any valid [`BufferEncoding`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/bdd02508ddb5eebcf701fdb8ffd6e84eabf47885/types/node/buffer.d.ts#L169) accepted by Node.js' `fs.writeFile` method. For example, to produce a binary png image:

```ts title="src/pages/astro-logo.png.ts" {6}
export async function get({ params, request }) {
export async function GET({ params, request }) {
const response = await fetch("https://docs.astro.build/assets/full-logo-light.png");
const buffer = Buffer.from(await response.arrayBuffer());
return {
Expand All @@ -45,7 +45,7 @@ You can also type your endpoint functions using the `APIRoute` type:
```ts
import type { APIRoute } from 'astro';

export const get: APIRoute = async ({ params, request }) => {
export const GET: APIRoute = async ({ params, request }) => {
...
```

Expand All @@ -58,7 +58,7 @@ import type { APIRoute } from 'astro';

const usernames = ["Sarah", "Chris", "Dan"]

export const get: APIRoute = ({ params, request }) => {
export const GET: APIRoute = ({ params, request }) => {
const id = params.id;
return {
body: JSON.stringify({
Expand All @@ -84,7 +84,7 @@ All endpoints receive a `request` property, but in static mode, you only have ac
```ts title="src/pages/request-path.json.ts"
import type { APIRoute } from 'astro';

export const get: APIRoute = ({ params, request }) => {
export const GET: APIRoute = ({ params, request }) => {
return {
body: JSON.stringify({
path: new URL(request.url).pathname
Expand All @@ -109,7 +109,7 @@ Server endpoints can access `params` without exporting `getStaticPaths`, and the
```js title="src/pages/[id].json.js"
import { getProduct } from '../db';

export async function get({ params }) {
export async function GET({ params }) {
const id = params.id;
const product = await getProduct(id);

Expand All @@ -134,7 +134,7 @@ This will respond to any request that matches the dynamic route. For example, if
In SSR mode, certain providers require the `Content-Type` header to return an image. In this case, use a `Response` object to specify a `headers` property. For example, to produce a binary `.png` image:

```ts title="src/pages/astro-logo.png.ts"
export async function get({ params, request }) {
export async function GET({ params, request }) {
const response = await fetch("https://docs.astro.build/assets/full-logo-light.png");
const buffer = Buffer.from(await response.arrayBuffer());
return new Response(buffer, {
Expand All @@ -144,40 +144,36 @@ export async function get({ params, request }) {
```

### HTTP methods
In addition to the `get` function, you can export a function with the name of any [HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods). When a request comes in, Astro will check the method and call the corresponding function.
In addition to the `GET` function, you can export a function with the name of any [HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods). When a request comes in, Astro will check the method and call the corresponding function.

You can also export an `all` function to match any method that doesn't have a corresponding exported function. If there is a request with no matching method, it will redirect to your site's [404 page](/en/core-concepts/astro-pages/#custom-404-error-page).

:::note
Since `delete` is a reserved word in JavaScript, export a `del` function to match the delete method.
:::
You can also export an `ALL` function to match any method that doesn't have a corresponding exported function. If there is a request with no matching method, it will redirect to your site's [404 page](/en/core-concepts/astro-pages/#custom-404-error-page).

```ts title="src/pages/methods.json.ts"
export const get: APIRoute = ({ params, request }) => {
export const GET: APIRoute = ({ params, request }) => {
return {
body: JSON.stringify({
message: "This was a GET!"
})
}
};

export const post: APIRoute = ({ request }) => {
export const POST: APIRoute = ({ request }) => {
return {
body: JSON.stringify({
message: "This was a POST!"
})
}
}

export const del: APIRoute = ({ request }) => {
export const DELETE: APIRoute = ({ request }) => {
return {
body: JSON.stringify({
message: "This was a DELETE!"
})
}
}

export const all: APIRoute = ({ request }) => {
export const ALL: APIRoute = ({ request }) => {
return {
body: JSON.stringify({
message: `This was a ${request.method}!`
Expand All @@ -192,7 +188,7 @@ export const all: APIRoute = ({ request }) => {
In SSR mode, the `request` property returns a fully usable [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object that refers to the current request. This allows you to accept data and check headers:

```ts title="src/pages/test-post.json.ts"
export const post: APIRoute = async ({ request }) => {
export const POST: APIRoute = async ({ request }) => {
if (request.headers.get("Content-Type") === "application/json") {
const body = await request.json();
const name = body.name;
Expand All @@ -212,7 +208,7 @@ The endpoint context exports a `redirect()` utility similar to `Astro.redirect`:
```js title="src/pages/links/[id].js" {14}
import { getLinkUrl } from '../db';

export async function get({ params, redirect }) {
export async function GET({ params, redirect }) {
const { id } = params;
const link = await getLinkUrl(id);

Expand Down
Loading
Loading