forked from denoland/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update APIs and documentation (denoland#340)
- Loading branch information
Showing
12 changed files
with
59 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,13 +86,11 @@ your connection string into the "Value" field. Now, press "Add". Your | |
environment variables is now set. | ||
|
||
Let's return back to the editor: to do this, go to the "Overview" tab via the | ||
left navigation menu, and press "Open Playground". Let's start by the `std/http` | ||
module so we can start serving HTTP requests: | ||
left navigation menu, and press "Open Playground". Let's start by serving HTTP | ||
requests using `Deno.serve()`: | ||
|
||
```ts | ||
import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts"; | ||
|
||
serve(async (req) => { | ||
Deno.serve(async (req) => { | ||
return new Response("Not Found", { status: 404 }); | ||
}); | ||
``` | ||
|
@@ -105,7 +103,6 @@ Next, let's import the Postgres module, read the connection string from the | |
environment variables, and create a connection pool. | ||
|
||
```ts | ||
import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts"; | ||
import * as postgres from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
// Get the connection string from the environment variable "DATABASE_URL" | ||
|
@@ -146,7 +143,7 @@ Now that we have a table, we can add the HTTP handlers for the GET and POST | |
endpoints. | ||
|
||
```ts | ||
serve(async (req) => { | ||
Deno.serve(async (req) => { | ||
// Parse the URL and check that the requested endpoint is /todos. If it is | ||
// not, return a 404 response. | ||
const url = new URL(req.url); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,7 +219,6 @@ for Deno, to run a GraphQL API server in Deno. | |
#### Run a GraphQL API server with gql | ||
|
||
```ts, ignore | ||
import { Server } from "https://deno.land/std@$STD_VERSION/http/server.ts"; | ||
import { GraphQLHTTP } from "https://deno.land/x/gql/mod.ts"; | ||
import { makeExecutableSchema } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { gql } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
@@ -238,23 +237,16 @@ const resolvers = { | |
const schema = makeExecutableSchema({ resolvers, typeDefs }); | ||
const s = new Server({ | ||
handler: async (req) => { | ||
const { pathname } = new URL(req.url); | ||
Deno.serve({ port: 3000 }, async () => { | ||
const { pathname } = new URL(req.url); | ||
return pathname === "/graphql" | ||
? await GraphQLHTTP<Request>({ | ||
schema, | ||
graphiql: true, | ||
})(req) | ||
: new Response("Not Found", { status: 404 }); | ||
}, | ||
port: 3000, | ||
return pathname === "/graphql" | ||
? await GraphQLHTTP<Request>({ | ||
schema, | ||
graphiql: true, | ||
})(req) | ||
: new Response("Not Found", { status: 404 }); | ||
}); | ||
s.listenAndServe(); | ||
console.log(`Started on http://localhost:3000`); | ||
``` | ||
|
||
### Client | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.