Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Building GET Endpoints for API | Section
Building APIs with Express.js

bookBuilding GET Endpoints for API

メニューを表示するにはスワイプしてください

GET endpoints are used to retrieve data from the server.

They return data without changing anything.

const users = [
  { id: 1, name: 'John' },
  { id: 2, name: 'Anna' }
];

app.get('/users', (req, res) => {
  res.json(users);
});

This endpoint returns all users.

You can also return a single item using a route parameter:

app.get('/users/:id', (req, res) => {
  const id = Number(req.params.id);

  const user = users.find(u => u.id === id);

  res.json(user);
});

Examples:

  • '/users': returns all users;
  • '/users/1': returns user with id 1.

GET endpoints are the most common way to read data in an API.

question mark

What is the purpose of a GET endpoint?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  12

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  12
some-alt