Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최은석
/
ossw-project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
채지성
2022-05-22 18:51:47 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
29af6147bc65bb189ea03446407286ee1e165248
29af6147
1 parent
28196742
fourth
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
13 deletions
server.js
server.js
View file @
29af614
...
...
@@ -12,29 +12,59 @@ app.listen(8080, function () {
})
let
items
=
[];
let
count
=
0
;
app
.
get
(
'/'
,
function
(
req
,
res
){
res
.
send
(
items
);
});
});
// 조회하는 RESTful API
app
.
post
(
'/post'
,
function
(
req
,
res
){
let
item
=
req
.
body
;
console
.
log
(
item
.
id
);
console
.
log
(
item
.
text
);
let
item
=
{
id
:
count
,
text
:
req
.
body
};
count
=
count
+
1
;
if
(
item
!=
""
){
items
.
push
(
item
);
}
console
.
log
(
"items: "
,
items
);
res
.
send
(
items
);
console
.
log
(
item
);
});
if
(
item
!=
""
){
items
.
push
(
item
);
console
.
log
(
"items: "
,
items
);
res
.
send
(
items
);
}
else
{
res
.
status
(
400
);
}
});
// 할 일을 생성하는 RESTfulAPI
app
.
put
(
'/put/:id'
,
function
(
req
,
res
){
let
id
=
req
.
params
.
id
;
console
.
log
(
id
);
let
iter_
=
0
;
items
.
forEach
((
elem
,
index
)
=>
{
if
(
elem
.
id
==
id
){
items
[
index
].
text
=
req
.
body
.
text
;
iter_
=
iter_
+
1
;
const
bool_
=
true
;
}
});
if
(
bool_
==
true
){
res
.
status
(
400
);
}
else
{
res
.
send
(
items
);
}
});
// todo에 적힌 내용을 수정하는 RESTfulAPI
app
.
delete
(
'/item/:id'
,
function
(
req
,
res
){
let
id
=
req
.
params
.
id
;
console
.
log
(
id
);
let
count
=
0
;
items
.
forEach
((
elem
,
index
)
=>
{
if
(
elem
.
id
==
id
){
items
.
splice
(
index
,
1
);
}
if
(
elem
.
id
==
id
){
items
.
splice
(
index
,
1
);
count
=
count
+
1
;
}
});
console
.
log
(
items
);
res
.
send
(
items
);
});
\ No newline at end of file
if
(
count
==
0
){
res
.
status
(
400
);
}
else
{
res
.
send
(
items
);
}
});
// todo를 삭제하는 RESTfulAPI
\ No newline at end of file
...
...
Please
register
or
login
to post a comment