: Node에서 쉽게 웹 서버를 개발할 수 있도록 도와주는 프레임워크
: 방금 설치한 express 를 사용하려면 함수를 불러와야함
import express from 'express'
import express from 'express' // 다른 파일에서 express 불러오기
const app = express() //express를 실행하여 실행된 결과를 새로운 변수 app 에 담아준것
----------------------------------------------------------------------
// app 사용 (app.post / app.delete/ app.update / app.get)
// '/'의 endpoint 를 가진 get 방식의 api 만들기
app.get('/', function (req, res) {
res.send('Hello World') // GET 요청이 들어왔을 때 Hello World라고 응답을 보내주는것
})
app.listen(3001) // 고유 포트번호 : 서버를 3001번 포트에서 실행되도록 설정하는것
1) node index.js 명령어로 서버를 켜기
2) postman에서 GET으로 http://localhost:3001
요청을 보내기
3) 응답으로 Hello World 를 받게됨
⭐️ 서버를 종료하고 싶다면 터미널에서 컨트롤 + c
눌러주면 됨
: URI(또는 경로) 및 특정한 HTTP 요청 메소드(GET, POST 등)인 특정 엔드포인트에 대한 클라이언트 요청에 애플리케이션이 응답하는 방법을 결정하는 것
: REST API를 쉽게 문서화하고 테스트할 수 있도록 도와주는 도구
import swaggerUi from 'swagger-ui-express';
import swaggerJsdoc from 'swagger-jsdoc'
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerJsdoc));
import express from 'express'
import {checkValidationPhone, getToken, sendTokenTOSMS} from './phone.js'
import swaggerUi from 'swagger-ui-express';
import swaggerJsdoc from 'swagger-jsdoc'
import {options} from './swagger/config.js'
const app = express()
app.use(express.json())
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerJsdoc(options)));
app.get('/', (req, res) => {res.send('Hello World!');});
export const options = {
definition: {
openapi: '3.0.0',
info: {
title: '나만의 미니프로젝트 API 명세서',
// title = swagger 접속했을때의 제목부분
version: '1.0.0',
},
},
apis: ['./swagger/*.js'], // files containing annotations as above
};
/**
* @openapi
* /board:
* get:
* summary: 게시글 가져오기
* tags: [Board]
* parameters:
* - in: query
* name: number
* type: int
* responses:
* 200:
* description: 성공
* content:
* application/json:
* schema:
* type: object
* properties:
* number:
* type: int
* example: 1
* writer:
* type: string
* example: 철수
* title:
* type: string
* example: 제목입니다!~~~
* contents:
* type: string
* example: 내용입니다!!!
*/
/**
* @openapi
* /board:
* post:
* description: Welcome to swagger-jsdoc!
* responses:
* 200:
* description: Returns a mysterious string.
*/