"페이크 REST API 서버 JSONPlaceholder"의 두 판 사이의 차이

 
(사용자 2명의 중간 판 9개는 보이지 않습니다)
3번째 줄: 3번째 줄:
* 페이크 REST API 서버
* 페이크 REST API 서버


<source lang='html'>
<syntaxhighlight lang='javascript' run>
<script src="//code.jquery.com/jquery.min.js"></script>
fetch('https://jsonplaceholder.typicode.com/posts/1')
<script>
   .then((response) => response.json())
var root = 'https://jsonplaceholder.typicode.com';
  .then((json) => {
$.ajax({
    for (const [k, v] of Object.entries(json)) {
  url: root + '/posts/1',
      console.log(k, ':', v);
   method: 'GET'
    }
}).then(function(data) {
  console.log(data);
});
});
// Object {userId: 1, id: 1, title: "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", body: "quia et suscipit↵suscipit recusandae consequuntur …strum rerum est autem sunt rem eveniet architecto"}
</syntaxhighlight>
</script>
</source>


==예시==
==예시==
39번째 줄: 35번째 줄:
* [[REST API 설계]]
* [[REST API 설계]]


==참고 자료==
==참고==
* http://jsonplaceholder.typicode.com/
* http://jsonplaceholder.typicode.com/


[[분류: REST API]]
[[분류: REST API]]
[[분류: jsonplaceholder]
[[분류: jsonplaceholder]]

2021년 12월 27일 (월) 23:36 기준 최신판

1 개요[ | ]

JSONPlaceholder
  • 페이크 REST API 서버
fetch('https://jsonplaceholder.typicode.com/posts/1')
  .then((response) => response.json())
  .then((json) => {
    for (const [k, v] of Object.entries(json)) {
      console.log(k, ':', v);
    }
});

2 예시[ | ]

동작 메소드 경로 예시URL
글목록 조회 GET /posts http://jsonplaceholder.typicode.com/posts
1번 글 조회 GET /posts/1 http://jsonplaceholder.typicode.com/posts/1
1번 글의 댓글목록 조회 GET /posts/1/comments http://jsonplaceholder.typicode.com/posts/1/comments
새글 입력 POST /posts http://jsonplaceholder.typicode.com/posts
1번 글 수정 PUT /posts/1 http://jsonplaceholder.typicode.com/posts/1
1번 글 수정 PATCH /posts/1 http://jsonplaceholder.typicode.com/posts/1
1번 글 삭제 DELETE /posts/1 http://jsonplaceholder.typicode.com/posts/1

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}