2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Deno と Postgres で REST API を作成

Last updated at Posted at 2020-05-19

次のページと同じことを行いました。
Creating your first REST API with Deno and Postgres

ソースコードはこちらです。
diogosouza / logrocket_deno_api

  1. ソースをクローンします。
git clone https://github.com/diogosouza/logrocket_deno_api.git
  1. コードの修正
config.js
// const env = Deno.env();

// export const APP_HOST = env.APP_HOST || "127.0.0.1";
// export const APP_PORT = env.APP_PORT || 4000;

export const APP_HOST = "127.0.0.1";
export const APP_PORT = 4000;
db/database.js
省略
port: 5432
省略
  1. サーバーの実行
deno run --allow-net index.js
  1. データの投入
curl -X POST -H "Content-Type: application/json" \
    -d '{"name":"Gold Star","brand":"Sapporo"}' \
    http://localhost:4000/beers
#
curl -X POST -H "Content-Type: application/json" \
    -d '{"name":"Ebisu","brand":"Sapporo"}' \
    http://localhost:4000/beers
#
curl -X POST -H "Content-Type: application/json" \
    -d '{"name":"Reserve","brand":"Sapporo"}' \
    http://localhost:4000/beers
  1. データの確認
curl -X GET http://localhost:4000/beers | jq .
  1. ブラウザーで、http://localhost:4000/beers/ にアクセス
    deno_postresql_may19.png
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?