제가 만든 웹 페이지에서 로그인화면으로 넘어가지 않습니다! 현상 처리법
개발자도구 → Application → 로컬스토리지에 있는 토큰삭제
프론트엔드 스쿨 기수가 진행되는 동안은 유지가 되나 그 외 기간은 중간에 서버를 닫을 수도 있습니다.
~url?limit=Number&skip=Number식의 쿼리를 날릴 수 있습니다.
limit = {몇개 불러올지}&skip={몇개 건너뛸지}
ex) 게시글 10개를 넘어가고 다음 5개의 게시글을 가져온다, 11번째 게시글부터 5개의 게시글 불러오기
/post/feed/?limit=5&skip=10
이 기능을 활용해서 페이지 처리를 할 수 있습니다!
0. 요청 url
https 서버 : https://api.mandarin.weniv.co.kr/
감귤마켓 URL : http://146.56.183.55:3000/
예시페이지 감귤마켓에서 사용중인 api와 실습용 api는 별개서버를 사용중입니다.
* 요청 예시
-login
const url = "https://api.mandarin.weniv.co.kr";
try{
const res = await fetch(url+"/user/login/", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body : JSON.stringify({
"user":{
"email": emailAddr.value,
"password": pw.value
}
})
});
const resJson = await res.json();
console.log(resJson);
} catch(err){
console.error(err);
}
JavaScript
복사
-image
const url = "https://mandarin.api.weniv.co.kr";
try {
const response = await fetch(url+"/image/uploadfiles", {
method: "POST",
body : formData
});
const data = await response.json();
for(let i of data) {
name.push(i["filename"]);
}
if(name.length > 1) {
return name.join(",");
} else {
return name[0];
}
} catch (err) {
console.error(err);
}
JavaScript
복사
1. 이미지
프로필 등록, 프로필 수정, 상품 등록 페이지 등 이미지 등록이 필요한 페이지에서 사용하는 API입니다. 이미지 등록이 필요한 페이지에서는 우선 서버에 이미지를 전송하면 숫자로 이루어진 filename을 포함하는 응답을 받을 수 있습니다. 그 filename을 다른 정보와 함께 서버에 전송해 줍니다.
*10MB 이상의 이미지는 업로드 할 수 없습니다.
예시 ) 프로필 등록 페이지에서의 사용 방법
1.
이미지를 서버에 전송합니다. (POST /image/uploadfile)
2.
숫자로 이루어진 filename을 응답받습니다. (2.png → 1640066364747.png)
3.
다른 정보와 함께 서버에 전송합니다. (POST /user)
filename은 “image”에 문자열로 전송합니다.
{
"user": {
"_id": String,
"email": String,
"hearts": [],
"isfollow": [],
"following": [],
"follower": [],
"password": String,
"username": String,
"accountname": String,
"intro": String,
"image": String // 예시) https://mandarin.api.weniv.co.kr/filename.확장자
}
}
JSON
복사
1.1 한 개의 이미지(프로필, 상품)
API
POST /image/uploadfile
JavaScript
복사
method, 전송 url
Req
key(name) : image
value : 이미지 파일(*.jpg, *.gif, *.png, *.jpeg, *.bmp, *.tif, *.heic)
//formdata의 키와 벨류를 의미합니다.
JSON
복사
body
{
"Content-type" : "multipart/form-data"
}
JSON
복사
header
Res
// SUCCESS
{
"fieldname": "image",
"originalname": "2.png",
"encoding": "7bit",
"mimetype": "image/png",
"destination": "uploadFiles/",
"filename": "1640066364747.png",
"path": "uploadFiles/1640066364747.png",
"size": 47406
}
// FAIL
// 이미지 파일(*.jpg, *.gif, *.png, *.jpeg, *.bmp, *.tif, *.heic) 확장자명이 다를 때
이미지 파일만 업로드가 가능합니다.
JSON
복사
1.2 여러개의 이미지(포스트)
여러개의 이미지를 등록하는 방법도 한개의 이미지를 등록하는 방법과 동일합니다. 우선 이미지를 서버에 전송하고 숫자로 이루어진 filename을 응답받습니다. 단, 이때 응답 받은 filename을 서버에 다시 전송할 때는 하나의 문자열로 전송되어야 합니다.
예를 들어, “1640066364747.png”와 “1640066364748.png”를 동시에 전송할 때는 둘을 합친 문자열로 전송해야 합니다. 이미지 이름을 합칠 때는 따옴표나 다른 기호를 통해 구분하여 합치면 나중에 이미지를 가져올 때 쉽게 사용할 수 있습니다.
“1640066364747.png,1640066364748.png” 이렇게 ,(따옴표)로 구분하여 문자열을 전송한 후 이미지를 불러올 때는 따옴표를 기준으로 split하여 사용할 수 있습니다. 편한 방법을 통해 문자열을 분리하여 사용해 보세요.
API
여러 이미지는 3개까지 받을 수 있습니다.
POST /image/uploadfiles
JavaScript
복사
method, 전송 url
Req
key : image
value : 이미지 파일(*.jpg, *.gif, *.png, *.jpeg, *.bmp, *.tif, *.heic)
JSON
복사
body
Res
// SUCCESS
{
"fieldname": "image",
"originalname": "2.png",
"encoding": "7bit",
"mimetype": "image/png",
"destination": "uploadFiles/",
"filename": "1640066364747.png",
"path": "uploadFiles/1640066364747.png",
"size": 47406
}
// FAIL
// 이미지 파일(*.jpg, *.gif, *.png, *.jpeg, *.bmp, *.tif, *.heic) 확장자명이 다를 때
이미지 파일만 업로드가 가능합니다.
// 3개 초과의 이미지를 업로드 했을 때
3개 이하의 파일을 업로드 하세요.
JSON
복사
1.3 이미지 보기
API
GET https://api.mandarin.weniv.co.kr/filename.이미지 확장자
JavaScript
복사
method, 전송 url
# url 그대로 사용
https://api.mandarin.weniv.co.kr/filename.이미지 확장자
SQL
복사
Res
// SUCCESS
JSON
복사
// FAIL
{
"status":404
}
JSON
복사
2. 유저
2.1 회원 가입
API
POST /user
JavaScript
복사
method, 전송 url
Req
{
"user": {
"username": String*,
"email": String*,
"password": String*,
"accountname": String*,
"intro": String,
"image": String // 예시) https://api.mandarin.weniv.co.kr/1641906557953.png
}
}
JSON
복사
body(json)
{
"Content-type" : "application/json"
}
JSON
복사
header
•
email, password, accountname, username 은 필수로 작성해야 합니다.
•
email은 이메일 형식에 맞게 작성해야 합니다.
•
accountname은 영문자, 숫자, 점(.), 밑줄(_)만 포함해야 합니다.
•
image가 없을 경우 기본 이미지가 적용됩니다. (image에 빈 문자열이 들어가면 서버에 저장된 기본 이미지로 적용됩니다.)
Res
// SUCCESS
{
"message": "회원가입 성공",
"user": {
"_id": String,
"username": String,
"email": String,
"accountname": String,
"intro": String,
"image": String,
}
}
// FAIL
// email, password, accountname, username 중 하나라도 작성하지 않을 경우
필수 입력사항을 입력해주세요.
// password를 6자 이상 입력하지 않을 경우
비밀번호는 6자 이상이어야 합니다.
// eamil 형식이 잘못될 경우
잘못된 이메일 형식입니다.
// 가입된 email일 경우
이미 가입된 이메일 주소입니다.
// accountname에 지정된 문자 이외의 문자가 들어갈 경우
영문, 숫자, 밑줄, 마침표만 사용할 수 있습니다.
// 가입된 accountname일 경우
이미 사용중인 계정 ID입니다.
JSON
복사
2.2 로그인
API
POST /user/login
JavaScript
복사
method, 전송 url
Req
{
"user":{
"email": String,
"password": String
}
}
JSON
복사
body(json)
{
"Content-type" : "application/json"
}
JSON
복사
header
•
email, password은 필수로 작성해야 합니다.
Res
// SUCCESS
{
"user": {
"_id": String,
"username": String,
"email": String,
"accountname": String,
"image": String,
"token": String
}
}
// FAIL
// email, password를 입력하지 않을 때
이메일 또는 비밀번호를 입력해주세요.
// email를 입력하지 않을 때
이메일을 입력해주세요.
// password를 입력하지 않을 때
비밀번호를 입력해주세요.
// email, password를 일치하지 않을 때
{
"message": "이메일 또는 비밀번호가 일치하지 않습니다.",
"status": 422
}
JSON
복사
2.3 프로필 정보 불러오기
API
GET /user/myinfo
JavaScript
복사
Req
{
"Authorization" : "Bearer {token}"
}
JavaScript
복사
header
Res
// SUCCESS
[
{
"user": {
"_id": String,
"username": String,
"accountname": String,
"image": String,
"isfollow": false,
"following": [],
"follower": [],
"followerCount": 0,
"followingCount": 0
}
}
]
JSON
복사
2.4 이메일 검증
API
POST /user/emailvalid
JavaScript
복사
Req
{
"user":{
"email": String
}
}
JSON
복사
body(json)
{
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
// 사용 가능한 이메일인 경우
{
"message": "사용 가능한 이메일 입니다."
}
// 가입한 이메일이 있는 경우
{
"message": "이미 가입된 이메일 주소 입니다."
}
f
// FAIL
{
"message": "잘못된 접근입니다."
}
JSON
복사
2.5 계정 검증
API
POST /user/accountnamevalid
JavaScript
복사
Req
{
"user":{
"accountname": String
}
}
JSON
복사
body(json)
{
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
// 사용 가능한 계정ID인 경우
{
"message": "사용 가능한 계정ID 입니다."
}
// 가입한 계정ID가 있는 경우
{
"message": "이미 가입된 계정ID 입니다."
}
// FAIL
{
"message": "잘못된 접근입니다."
}
JSON
복사
3. 프로필
3.1 프로필 수정
API
PUT /user
JavaScript
복사
method, 전송 url
Req
{
"user":{
"username": String,
"accountname": String,
"intro": String,
"image": String
}
}
JSON
복사
body(json)
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"user": {
"_id": String,
"username": String,
"accountname": String,
"intro": String,
"image": String,
"following": [],
"follower": [],
"followerCount": Number,
"followingCount": Number
}
}
// FAIL
// 가입된 accountname일 경우
이미 사용중이 계정 ID입니다.
JSON
복사
3.2 개인 프로필
API
GET /profile/:accountname
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : `Bearer ${token}`,
"Content-type" : "application/json"
}
JavaScript
복사
header
Res
// SUCCESS
{
"profile": {
"_id": String,
"username": String,
"accountname": String,
"intro": String,
"image": String,
"isfollow": Boolean,
"following": [],
"follower": [],
"followerCount": Number,
"followingCount": Number
}
}
// FAIL
// 계정이 존재하지 않을 때
해당 계정이 존재하지 않습니다.
JSON
복사
3.3 팔로우
API
POST /profile/:accountname/follow
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
// follow 한 사용자의 프로필
{
"profile": {
"_id": String,
"username": String,
"accountname": String,
"intro": String,
"image": String,
"isfollow": Boolean,
"following": [],
"follower": [
"접속한 사용자의 id"
],
"followerCount": 1,
"followingCount": 0
}
}
// FAIL
// 계정이 존재하지 않을 때
해당 계정이 존재하지 않습니다.
// 자신을 팔로우하려 할 때
{
"message": "자기 자신을 팔로우 할 수 없습니다."
}
JSON
복사
3.4 언팔로우
API
DELETE /profile/:accountname/unfollow
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
// follow 한 사용자의 프로필
{
"profile": {
"_id": String,
"username": String,
"accountname": String,
"intro": String,
"image": String,
"isfollow": Boolean,
"following": [],
"follower": [],
"followerCount": 0,
"followingCount": 0
}
}
// FAIL
// 계정이 존재하지 않을 때
해당 계정이 존재하지 않습니다.
JSON
복사
// SUCCESS
// 접속한 사용자의 프로필
{
"profile": {
"_id": String,
"username": String,
"accountname": String,
"intro": String,
"image": String,
"isfollow": Boolean,
"following": [],
"follower": [],
"followerCount": 0,
"followingCount": 0
}
}
// FAIL
// 계정이 존재하지 않을 때
해당 계정이 존재하지 않습니다.
JSON
복사
3.5 팔로잉 리스트(내가 팔로우한 사용자 목록)
API
GET /profile/:accountname/following
// paging limit skip
GET /profile/:accountname/following?limit=Number&skip=Number
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : `Bearer ${token}`,
"Content-type" : "application/json"
}
JavaScript
복사
header
Res
// SUCCESS
// following 한 사용자가 있을 때
[
{
"_id": String,
"username": String,
"accountname": String,
"intro": String,
"image": String,
"isfollow": Boolean,
"following": [],
"follower": [
"접속한 사용자의 id"
],
"followerCount": 1,
"followingCount": 0
}
]
// following 한 사용자가 없을 때
[]
// FAIL
// 계정이 존재하지 않을 때
해당 계정이 존재하지 않습니다.
JSON
복사
3.6 팔로워 리스트(나를 팔로우한 사용자 목록)
API
GET /profile/:accountname/follower
// paging limit skip
GET /profile/:accountname/follower/?limit=Number&skip=Number
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : `Bearer ${token}`,
"Content-type" : "application/json"
}
JavaScript
복사
header
Res
// SUCCESS
// follower 한 사용자가 있을 때
[
{
"_id": String,
"username": String,
"accountname": String,
"intro": String,
"image": String,
"isfollow": Boolean,
"following": [],
"follower": [
"접속한 사용자의 id"
],
"followerCount": 1,
"followingCount": 0
},
{
"_id": String,
"username": String,
"accountname": String,
"intro": String,
"image": String,
"isfollow": Boolean,
"following": [],
"follower": [
"접속한 사용자의 id"
],
"followerCount": 1,
"followingCount": 0
},
]
// follower 한 사용자가 없을 때
[]
// FAIL
// 계정이 존재하지 않을 때
해당 계정이 존재하지 않습니다.
JSON
복사
4. 검색
4.1 유저 검색
API
GET /user/searchuser/?keyword=keyword
JavaScript
복사
method, 전송 url
•
keyword에 검색어를 입력합니다.
•
keyword에는 accountname, username을 검색할 수 있습니다.
Req
{
"Authorization" : `Bearer ${token}`,
"Content-type" : "application/json"
}
JavaScript
복사
header
Res
// SUCCESS
[
{
"_id": String,
"username": String,
"accountname": String,
"following": [],
"follower": [],
"followerCount": Number,
"followingCount": Number
}
]
JSON
복사
5. 게시글
5.1 게시글 작성
API
POST /post
Plain Text
복사
method, 전송 url
Req
{
"post": {
"content": String,
"image": String //"imageurl1, imageurl2" 형식으로
}
}
JSON
복사
body(json)
{
"Authorization" : `Bearer ${token}`,
"Content-type" : "application/json"
}
JavaScript
복사
header
Res
// SUCCESS
{
"post": [
{
"id": String,
"content": String,
"image": String,
"createdAt": String,
"updatedAt": String,
"hearted": false,
"heartCount": 0,
"commentCount": 0,
"author": {
"_id": "작성자 id",
"username": "2",
"accountname": "2",
"following": [],
"follower": [
"follower id"
],
"followerCount": 1,
"followingCount": 0
}
}
]
}
// FAIL
// 내용 또는 이미지를 입력하지 않을 때
내용 또는 이미지를 입력해주세요.
JSON
복사
5.2 팔로잉 게시글 목록(피드)
내가 팔로우하고 있는 유저의 게시글 목록입니다.
API
GET /post/feed
// paging limit skip
GET /post/feed/?limit=Number&skip=Number
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
// follow 한 사용자가 있을 때
{
"posts": [
{
"id": String,
"content": "안녕하세요. 2 입니다.",
"image": String,
"createdAt": String,
"updatedAt": String,
"hearted": false,
"heartCount": 0,
"commentCount": 0,
"author": {
"_id": "작성자 id",
"username": "2",
"accountname": "2",
"following": [],
"follower": [
"follower id"
],
"followerCount": 1,
"followingCount": 0
}
}
]
}
// follow 한 사용자가 없을 때
{
"posts": []
}
JSON
복사
5.3 나의 게시글 목록
API
GET /post/:accountname/userpost
// paging limit skip
GET /post/:accountname/userpost/?limit=Number&skip=Number
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"post": [
{
"id": String,
"content": "안녕하세요. 2 입니다.",
"image": String,
"createdAt": String,
"updatedAt": String,
"hearted": false,
"heartCount": 0,
"commentCount": 0,
"author": {
"_id": "작성자 id",
"username": "2",
"accountname": "2",
"following": [],
"follower": [
"follower id"
],
"followerCount": 1,
"followingCount": 0
}
}
]
}
// 해당 계정의 게시물이 존재하지 않을 때
{
"post":[]
}
// FAIL
// 해당 계정이 존재하지 않을 때
해당 계정이 존재하지 않습니다.
JSON
복사
5.4 게시글 상세
API
GET /post/:post_id
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"post": [
{
"id": String,
"content": String,
"image": String,
"createdAt": String,
"updatedAt": String,
"hearted": false,
"heartCount": 0,
"commentCount": 0,
"author": {
"_id": "작성자 id",
"username": "2",
"accountname": "2",
"following": [],
"follower": [
"follower id"
],
"followerCount": 1,
"followingCount": 0
}
}
]
}
// FAIL
// 게시글이 존재하지 않을 때
존재하지 않는 게시글입니다.
JSON
복사
5.5 게시글 수정
API
PUT /post/:post_id
JavaScript
복사
method, 전송 url
Req
{
"post": {
"content": String,
"image": String
}
}
JSON
복사
body(json)
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"post": [
{
"id": String,
"content": String,
"image": String,
"createdAt": String,
"updatedAt": String,
"hearted": false,
"heartCount": 0,
"commentCount": 0,
"author": {
"_id": "작성자 id",
"username": "2",
"accountname": "2",
"following": [],
"follower": [
"follower id"
],
"followerCount": 1,
"followingCount": 0
}
}
]
}
// FAIL
// 게시글이 존재하지 않을 때
존재하지 않는 게시글입니다.
// 다른 사용자가 해당 게시물을 수정할 경우
잘못된 요청입니다. 로그인 정보를 확인하세요.
JSON
복사
5.6 게시글 삭제
API
DELETE /post/:post_id
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
삭제되었습니다.
// FAIL
// 게시글이 존재하지 않을 때
존재하지 않는 게시글입니다.
// 다른 사용자가 해당 게시물을 수정할 경우
잘못된 요청입니다. 로그인 정보를 확인하세요.
JSON
복사
5.7 게시글 신고
API
POST /post/:post_id/report
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"report": {
"post": "포스트 id"
}
}
// FAIL
// 게시글이 존재하지 않을 때
존재하지 않는 게시글입니다.
JSON
복사
6. 좋아요
6.1 좋아요
API
POST /post/:post_id/heart
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"post": {
"id": String,
"content": String,
"createdAt": String,
"updatedAt": String,
"hearted": true,
"heartCount": 1,
"commentCount": 0,
"author": {
"_id": "작성자 id",
"username": "2",
"accountname": "2",
"intro": "2",
"image": "2",
"following": [],
"follower": [
"팔로워 한 사용자의 id"
],
"followerCount": 1,
"followingCount": 0
}
}
}
// FAIL
// 게시글이 존재하지 않을 때
존재하지 않는 게시글입니다.
JSON
복사
6.2 좋아요 취소
API
DELETE /post/:post_id/unheart
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"post": {
"id": "61c0252b8ec189519824a9b1",
"content": "2@naver.com",
"createdAt": "2021-12-20T06:39:39.929Z",
"updatedAt": "2021-12-20T08:05:12.727Z",
"hearted": false,
"heartCount": 0,
"commentCount": 0,
"author": {
"_id": "작성자 id",
"username": "2",
"accountname": "2",
"intro": "2",
"image": "2",
"following": [],
"follower": [
"팔로워 한 사용자의 id"
],
"followerCount": 1,
"followingCount": 0
}
}
}
// FAIL
// 게시글이 존재하지 않을 때
존재하지 않는 게시글입니다.
JSON
복사
7. 댓글
7.1 댓글 작성
API
POST /post/:post_id/comments
JavaScript
복사
method, 전송 url
Req
{
"comment":{
"content":String
}
}
JSON
복사
body(json)
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"comment": {
"id": Sting,
"content": Sting,
"createdAt": Sting,
"author": {
"_id": "작성자 id",
"username": "1",
"accountname": "1",
"intro": "1",
"image": "1",
"following": [],
"follower": [],
"followerCount": 0,
"followingCount": 0
}
}
}
// FAIL
// 게시물이 존재하지 않을 때
존재하지 않는 게시글입니다.
// 댓글을 입력하지 않을 때
댓글을 입력해주세요.
JSON
복사
7.2 댓글 리스트
API
// 기본값은 10개만 불러옵니다.
GET /post/:post_id/comments
// paging limit skip
GET /post/:post_id/comments/?limit=Number&skip=Number
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
// 댓글이 존재하는 경우
{
"comment": [
{
"id": String,
"content": String,
"createdAt": "2021-12-20T06:10:26.803Z",
"author": {
"_id": "작성자 id",
"username": "1",
"accountname": "1",
"intro": "1",
"image": "1",
"following": [],
"follower": [],
"followerCount": 0,
"followingCount": 0
}
}
]
}
// 댓글이 존재하지 않는 경우
{
"comment": []
}
// FAIL
// 게시물이 존재하지 않을 때
존재하지 않는 게시글입니다.
JSON
복사
7.3 댓글 삭제
API
DELETE /post/:post_id/comments/:comment_id
Plain Text
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
댓글이 삭제되었습니다.
// FAIL
// 다른 사용자의 댓글을 삭제하려고 할 때
댓글 작성자만 댓글을 삭제할 수 있습니다.
// 게시글이 존재하지 않을 때
존재하지 않는 게시글입니다.
// 댓글이 존재하지 않을 때
댓글이 존재하지 않습니다.
JSON
복사
7.4 댓글 신고
API
POST /post/:post_id/comments/:comment_id/report
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"report": {
"comment": "댓글 id"
}
}
// FAIL
// 게시글이 존재하지 않을 때
존재하지 않는 게시글입니다.
// 댓글이 존재하지 않을 때
댓글이 존재하지 않습니다.
JSON
복사
8. 상품
8.1 상품 등록
API
POST /product
JavaScript
복사
method, 전송 url
Req
{
"product":{
"itemName": String,
"price": Number,//1원 이상
"link": String,
"itemImage": String
}
}
JSON
복사
body(json)
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"product": {
"id": String,
"itemName": String,
"price": Number,
"link": String,
"itemImage": String,
"author": {
"_id": "작성자 id",
"username": "2",
"accountname": "2",
"intro": "2",
"image": "2",
"following": [],
"follower": [
"팔로워 한 사용자의 id"
],
"followerCount": 1,
"followingCount": 0
}
}
}
// FAIL
// itemName, price, link, itemImage 중 하나라도 입력하지 않았을 때
필수 입력사항을 입력해주세요.
// price를 String으로 입력했을 때
가격은 숫자로 입력하셔야 합니다.
JSON
복사
8.2 상품 리스트
API
GET /product/:accountname
// paging limit skip
GET /product/:accountname/?limit=Number&skip=Number
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
회// SUCCESS
// 상품이 있을 때
{
"data" : Number,
"product": [
{
"id": String,
"itemName": String,
"price": Number,
"link": String,
"itemImage": String,
"author": {
"_id": "작성자 id",
"username": "2",
"accountname": "2",
"intro": "2",
"image": "2",
"following": [],
"follower": [
"팔로워 한 사용자의 id"
],
"followerCount": 1,
"followingCount": 0
}
}
]
}
// 상품이 없을 때
{
"data" : 0,
"product": []
}
JSON
복사
8.3 상품 상세
API
GET /product/detail/:product_id
JavaScript
복사
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"product":{
"id": String,
"itemName": String,
"price": Number,
"link": String,
"itemImage": String,
"author": {
"_id": "작성자 id",
"username": "2",
"accountname": "2",
"intro": "2",
"image": "2",
"following": [],
"follower": [
"팔로워 한 사용자의 id"
],
"followerCount": 1,
"followingCount": 0
}
}
}
JSON
복사
8.4 상품 수정
API
PUT /product/:product_id
JavaScript
복사
method, 전송 url
Req
{
"product": {
"itemName": String,
"price": Number,
"link": String,
"itemImage": String
}
}
JSON
복사
body(json)
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
{
"product": {
"id": String,
"itemName": String,
"price": Number,
"link": String,
"itemImage": String,
"author": {
"_id": "작성자 id",
"username": "2",
"accountname": "2",
"intro": "2",
"image": "2",
"following": [],
"follower": [
"팔로워 한 사용자의 id"
],
"followerCount": 1,
"followingCount": 0
}
}
}
// FAIL
// 상품이 없을 때
등록된 상품이 없습니다.
// 상품을 등록한 사용자가 아닐 때
잘못된 요청입니다. 로그인 정보를 확인하세요.
JSON
복사
8.5 상품 삭제
API
DELETE /product/:product_id
JavaScript
복사
method, 전송 url
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// SUCCESS
삭제되었습니다.
// FAIL
// 상품이 없을 때
등록된 상품이 없습니다.
// 상품을 등록한 사용자가 아닐 때
잘못된 요청입니다. 로그인 정보를 확인하세요.
JSON
복사
9. 토큰 검증
API
GET user/checktoken
JavaScript
복사
Req
{
"Authorization" : "Bearer {token}",
"Content-type" : "application/json"
}
JSON
복사
header
Res
// 토큰이 유효한 경우
{
"isValid":true
}
// 토큰이 유효하지않은 경우
{
"isValid":false
}
JSON
복사
에러코드
도움?
코드가 많이 엉망진창입니다. 참고만하셔요