목록Backend (45)
나의 발자취

지난 포스팅: 2024.10.15 - [Backend] - [Node.js] GraphQL Schema 설계, mutation 타입 [Node.js] GraphQL Schema 설계, mutation 타입일단 냅다 올리고 시작type Query { // 예약어 hello: String getPost(id: ID!): Post}type Post { // 커스텀 자료형 id: ID! title: String! content: String!}type Mutation { // 예약어 createPost(input: PostInput): Post updatePost(id: ID!, inpuwildguess.tistory.com ORM이란?Object-Relational Mapping 대표적인 ORM으로는 P..

일단 냅다 올리고 시작type Query { // 예약어 hello: String getPost(id: ID!): Post}type Post { // 커스텀 자료형 id: ID! title: String! content: String!}type Mutation { // 예약어 createPost(input: PostInput): Post updatePost(id: ID!, input: PostInput) : Post deletePost(id: ID!)}input PostInput { title: String! content: String!}// 기본 타입// Int: 32bit 정수형// Float: 부동 소수점 숫자// String// Boolea..

GraphQL의 특징 단일 엔드포인트필요한 데이터만 요청오버패칭 언더페칭 문제 해결배치요청REST api를 쓰게 되면, 한 화면에 포스트와 댓글을 다 보여줘야하므로GET http://localhost:3000/posts/2 와,GET http://localhost:3000/posts/2/comments 두 개를 모두 요청해야한다. 하지만 GraphQL의 경우,{ getPosts(ID:2) { titlecontentauth}getcomments(ID:2){content}로 요청이 가능하다는 것 ! 버전관리 필요 없음실시간 데이터처리스키마 정의type Query {hello: StringgetPosts(id: ID) : Post 프로젝트 시작 1. 프로젝트 준비: 경로를 열고, npm init -y 실행2..

1. create_sql에 새로운 DB(comments)를 생성해준다. CREATE TABLE IF NOT EXISTS comments ( id INTEGER PRIMARY KEY AUTOINCREMENT, content TEXT NOT NULL, postId INTEGER, FOREIGN KEY(postId) REFERENCES posts(id) ); 2. DB 생성된 것 확인 3. 코드 구현// 특정 포스트 댓글 추가app.post("/posts/:id/comments", (req, res) => { const { content } = req.body; // req.body.content -> content const postId = req.params.id; const stmt = db.pr..

npm i better-sqlite3 패키지를 설치해준다. 기존의 RESTapi와 비슷하면서도 다르다. 다른 점 위주로 작성해보겠다.일단 당연히 sqlite3를 이제 쓰지 않을 것이기 때문에 해당 부분은 Database 변수로 선언해주는 부분이 다르다.그리고 const app 부분부터 create_sql 쿼리부분까지는 내용이 같으니 복붙해준다. 아래에 db.exec(create_sql); 을 해준다. GET /posts - 게시글 목록 가져오기그리고 그 아래에 1번 GET 기능을 아래 부분만 복붙해준다. 그리고 코드 작성// 1. GET /posts 게시글 목록app.get("/posts", (req, res) => { const page = req.query.page ? parseInt(req.q..

POST /posts - 게시글 쓰기아래와 같이 api 기본 틀을 설계해준다. (깃허브에 커밋 이력 참고)https://github.com/est22/backend/commit/5056afee59d19a4ff809b78190a2904ee10f17d8) 1. curl -X POST -H "Content-Type: application/json" -d '{"title":"Test1", "content":"test content", "author":"lia"}' http://localhost:3000/posts를 입력하고 엔터를 치면, 아래와 같이 line 73에 입력한 대로 결과가 나온다. 2. curl http://localhost:3000/posts로 GET 요청을 하면, 현재 존재하는 데이터들을 jso..
CURL은 Command line에서 HTTP 요청을 보내고 서버 응답을 확인하는 도구이다. Postman은 이것의 gui 버전이라고 생각하면 된다. 버그와 같은 이슈가 발견되어 지라를 작성할 때 CURL을 잘 사용한다. curl GET 요청 curl curl http://jsonplaceholder.typicode.com/postscurl https://www.naver.com curl POST 요청curl -X POST -H 서버에 POST 요청을 보낼 때 전송할 데이터를 지정을 하고 싶은 경우, -d 옵션을 쓰고 JSON 형식의 데이터를 적어주면 된다. (여기서 -d 는 data를 뜻한다.)curl -X POST -H "Content-Type: application/json" -d '{실제 날..

API의 종류https://medium.com/@yusufacarr18/whats-api-api-types-most-popular-api-services-rest-vs-soap-what-s-the-difference-1bd6a685afa1 What’s API ? API Types, Most Popular API Services, REST vs SOAP : What’s the DifferenceWhat’s API?medium.com1. SOAP API = Simple Object Access Protocol은 XML기반 프로토콜을 사용하는 API이다.조금 더 엄격한 보안 구조를 이용해 데이터를 전달하는 API 구조이며, 강한 보안 구조를 가지고 있기 때문에 Rest API보다 설정이 더 어렵다. 2. RE..