Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- spring builder
- Docker Windows 설치
- Spring DTO
- Spring Controller return
- 코드 중복제거
- JPA Update\
- spring
- react
- Spring JPA
- javascrpit 기초
- react Page
- Javascript
- springbatch chunk
- editor Quill
- SpringBatch 스키마
- react Quill
- 텍스트가 많은 경우
- spring security
- springbatch
- react quill custom
- react link
- react jsx if
- Spring CORS
- react react-router-dom v6
- Spring Entity
- step 테이블
- JPA Insert
- javascript 함수
- react forwardRef
- javascript 기초
Archives
- Today
- Total
천천히 알아보는 코딩공부
[React] API 연동 - axios 본문
API 호출하기 위해서 라이브러리를 설치해보자
https://meetup.toast.com/posts/92 - rest api
npm install axios
axios를 사용해서 GET, PUT, POST, DELETE 등의 메서드로 API 요청을 할 수 있다.
- GET: 데이터 조회
- POST: 데이터 등록
- PUT: 데이터 수정
- DELETE: 데이터 제거
axios 사용법
Get 방식
import axios from 'axios';
axios.get('https://localhost:4000/sendlist/todo',
{userId: userId},
{ withCredentials: true }
)
Post
axios.post('/users', {
username: 'blabla',
name: 'blabla'
});
혹은
axios.post(API_URL + "receiveData", JSON.stringify(data),
{ headers: { "Content-Type": "application/json; charset=UTF-8" },
params: { userID: 1 }, //Add userID as a param
}).then(response=> console.log("repsonse", response.status))
동기로 Post 날리기 비동기 X
API.js
export async function PostAPI(URL, body)
{
var result = await axios.post(URL, body)
result result
}
- async, await 동기로 해주기위함
호출시에도 await axios.post(URL, body)
로 작업 시 순서대로 작업이 진행된다. 값 return 도 가능+
'React > 기초' 카테고리의 다른 글
| [react] jsx if문 정리 (0) | 2022.10.27 |
|---|---|
| [React] jsx 반복문 / for 반복문 (0) | 2022.09.26 |
| [react] Hooks - useState, useEffect (0) | 2022.09.05 |
| [react] react Event (1) - onClick (0) | 2022.08.10 |
| [react] next.js 세팅하기 (0) | 2022.08.02 |
Comments