๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๊ฐœ๋ฐœ66

RESTful API ์„ค๊ณ„ ์›์น™ / ๋„ค์ด๋ฐ ๊ทœ์น™ RESTful API ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ๋ฐฉ์‹์— ๋Œ€ํ•œ ์•„ํ‚คํ…์ฒ˜ ์Šคํƒ€์ผ RESTful API Naming ๋ฆฌ์†Œ์Šค ํ‘œํ˜„์— ๋ช…์‚ฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ผ. ๊ณ„์ธต๊ด€๊ณ„๋ฅผ ๊ตฌ๋ถ„์ง“๊ธฐ ์œ„ํ•ด ์Šฌ๋ž˜์‹œ(/)๋ฅผ ์‚ฌ์šฉํ•˜๋ผ. URI ๋งˆ์ง€๋ง‰์— ์Šฌ๋ž˜์‹œ๋ฅผ ๋ถ™์ด์ง€ ๋งˆ๋ผ. ํ•˜์ดํ”ˆ(-) ๊ธฐํ˜ธ๋ฅผ ์‚ฌ์šฉํ•ด ๊ฐ€๋…์„ฑ์„ ๋†’์—ฌ๋ผ. ์–ธ๋”์Šค์ฝ”์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋งˆ๋ผ. ์†Œ๋ฌธ์ž๋งŒ์„ ์‚ฌ์šฉํ•˜๋ผ. ๋ฆฌ์†Œ์Šค ํ‘œํ˜„์— ๋ช…์‚ฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ผ. RESTful URI ๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๋Š” ๋ฆฌ์†Œ์Šค๋Š” ์ˆ˜ํ–‰๋˜๋Š” ํ–‰์œ„๊ฐ€ ์•„๋‹ˆ๋ผ ๊ฐ์ฒด์ด๋‹ค. ์ด ๋ฆฌ์†Œ์Šค๊ฐ€ ์–ด๋Š ๋ฒ”์ฃผ์— ํ•ด๋‹นํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ๊ทธ ๋ฒ”์ฃผ์— ๋งž๋Š” ๋„ค์ด๋ฐ ์ปจ๋ฒค์…˜์„ ์ผ๊ด€๋˜๊ฒŒ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. โ˜‘๏ธ ๋ฌธ์„œ(Document) ๋‹จ์ผ ๊ฐœ๋…(ํŒŒ์ผ ํ•˜๋‚˜, ๊ฐ์ฒด ์ธ์Šคํ„ด์Šค, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค row) ๋‹จ์ˆ˜ ์‚ฌ์šฉ(/device-management, /user-managemen.. 2023. 5. 8.
HTTP RESTful API / ์•ˆ์ „์„ฑ๊ณผ ๋ฉฑ๋“ฑ์„ฑ REST(Representational State Transfer) ์ž์›์„ ์ด๋ฆ„์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ํ•ด๋‹น ์ž์›์˜ ์ƒํƒœ๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ๋ชจ๋“  ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค. HTTP ์—์„œ์˜ REST ๋ž€? 1. HTTP URI(Uniform Resource Identifier)๋กœ ์ž์›(Resource)์„ ๋ช…์‹œ 2. HTTP Method(POST, GET, PUT, DELETE, PATCH ๋“ฑ)๋กœ 3. ํ•ด๋‹น ์ž์›(URI)์— ๋Œ€ํ•œ CRUD Operation์„ ์ ์šฉํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธ HTTP REST ๊ตฌ์„ฑ์š”์†Œ ์ž์›(Resource): HTTP URI ์ž์›์— ๋Œ€ํ•œ ํ–‰์œ„(Verb): HTTP Method ํ‘œํ˜„(Representations) HTTP REST ํŠน์ง• ์„œ๋ฒ„-ํด๋ผ์ด์–ธํŠธ ๊ตฌ์กฐ(Server-Client) ๋ฌด์ƒํƒœ์„ฑ(Stateless) ์บ์‹œ ์ฒ˜๋ฆฌ.. 2023. 2. 22.
Spring boot with Swagger 3.0 OpenAPI๋ž€? OpenAPI Specification(OAS)๋ผ๊ณ ๋„ ํ•˜๋Š” OpenAPI๋Š” RESTful API๋ฅผ ๊ธฐ์ •์˜๋œ ๊ทœ์น™์— ๋งž๊ฒŒ API Spec์„ json์ด๋‚˜ yaml๋กœ ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ์‹์„ ์˜๋ฏธํ•œ๋‹ค. RESTful API ๋ฅผ ๊ธฐ์ˆ ํ•˜๋Š” ํ‘œ์ค€์œผ๋กœ ์„œ๋น„์Šค์—์„œ ์ œ๊ณตํ•˜๋Š” API ์˜ ๊ธฐ๋Šฅ๊ณผ End Point ๋ฅผ ๊ฐœ๋ฐœ์ž๋‚˜ ์‹œ์Šคํ…œ์ด ์ž๋™์œผ๋กœ ๋ฐœ๊ฒฌํ•˜๊ณ  ์ฒ˜๋ฆฌํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•œ๋‹ค. ์ „์—๋Š” Swagger 2.0๊ณผ ๊ฐ™์€ ์ด๋ฆ„์œผ๋กœ ๋ถˆ๋ ธ๋‹ค๊ฐ€ 3.0๋ฒ„์ „์œผ๋กœ ์˜ฌ๋ผ์˜ค๋ฉด์„œ OpenAPI 3.0 Specification(๋˜๋Š” Swagger 3.0)์œผ๋กœ ์นญํ•œ๋‹ค. ๐Ÿ”Ž Open API(Open Application Programming Interface, ๊ณต๊ฐœ API) ๋ˆ„๊ตฌ๋‚˜ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ณต๊ฐœ๋œ API๋ฅผ ๋งํ•œ๋‹ค. Public.. 2022. 11. 3.
์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์œ ์šฉํ•œ ํ•จ์ˆ˜ ๋ชจ์Œ ๊ฐ์ฒด ํ‚ค ์ด๋ฆ„ ๋ณ€๊ฒฝํ•˜๊ธฐ โœ๏ธ ๊ฐ์ฒด const originObj = { old1: '๊ฐ’1', old2: '๊ฐ’2', old3: '๊ฐ’3', old4: '๊ฐ’4', old5: '๊ฐ’5' }; const func = ({old1: new1, old2: new2, ...rest}) => { return {new1, new2, rest}; } const newObj = func(originObj); console.log(newObj); โœ๏ธ ๊ฐ์ฒด ๋ฐฐ์—ด const originList = [{ old1: '๊ฐ’1', old2: '๊ฐ’2', old3: '๊ฐ’3', old4: '๊ฐ’4', old5: '๊ฐ’5' }, { old1: '๊ฐ’1', old2: '๊ฐ’2', old3: '๊ฐ’3', old4: '๊ฐ’4', old5: '๊ฐ’5' }]; con.. 2022. 8. 29.
in-memory / cache / redis / memcached in-memory ์ปดํ“จํ„ฐ ๋ฉ”์ธ ๋ฉ”๋ชจ๋ฆฌ์ธ RAM์— ๋ฐ์ดํ„ฐ๋ฅผ ์˜ฌ๋ ค์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. in-memory DB ๋ฉ”๋ชจ๋ฆฌ์™€ ๋””์Šคํฌ ๊ฐ„ ๋ณ‘๋ชฉ์ด ์—†์–ด SSD, HDD ๊ฐ™์€ ์ €์žฅ๊ณต๊ฐ„์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ๋ณด๋‹ค ์†๋„๊ฐ€ ๋น ๋ฅด๋‹ค. ์†๋„๊ฐ€ ๋น ๋ฅธ ๋Œ€์‹  ๋น„์šฉ์ด ๋น„์‹ธ ํฐ ์šฉ๋Ÿ‰์œผ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ์—๋Š” ๋ฌด๋ฆฌ๊ฐ€ ์žˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ ์˜์†์„ฑ์„ ๋ณด์žฅํ•˜์ง€ ์•Š์•„ ๋ฐ์ดํ„ฐ๊ฐ€ ์œ ์‹ค๋  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ์— ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ๊ณ  ์“ฐ๋Š” DB๋ฉด in-memory DB๋ผ๊ณ  ํ•œ๋‹ค. RDBMS์ธ MySQL์—์„œ๋„ in-memory ๋ชจ๋“œ๋ฅผ ์ง€์›ํ•˜๊ณ , NoSQL์ธ Redis๋„ in-memory DB์ด๋‹ค. โœ” disk-based DB ์™ธ๋ถ€ ์ €์žฅ ์žฅ์น˜์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์–ด์„œ ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ฆฌ๊ณ , ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ผ๊ฐ„ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์–ด์„œ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์†๋„๊ฐ€ ๋Š๋ฆฌ๋‹ค. in-memor.. 2022. 7. 10.
์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ํ’€์ด ๋ชจ์Œ ๋‘ ์ •์ˆ˜ ์‚ฌ์ด์— ์†ํ•œ ์ •์ˆ˜์˜ ํ•ฉ ๊ตฌํ•˜๊ธฐ function solution(a, b) { return (a + b) * (Math.abs(b - a) + 1) / 2; } ๋‘ ๋ฒกํ„ฐ์˜ ๊ฐ ์„ฑ๋ถ„๋ผ๋ฆฌ์˜ ๊ณฑ์˜ ํ•ฉ์‚ฐ(๋‚ด์ ) ๊ตฌํ•˜๊ธฐ function solution(a, b) { // a, b ๋ฐฐ์—ด์˜ ๊ธธ์ด๊ฐ€ ๋™์ผํ•จ์œผ๋กœ ๊ฐ€์ • return a.reduce((acc, _, i) => acc += a[i] * b[i], 0); } 0๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆซ์ž ์ค‘ ์—†๋Š” ์ˆซ์ž ๋”ํ•˜๊ธฐ function solution(numbers) { return 45 - numbers.reduce((cur, acc) => cur + acc, 0); } 2022. 7. 8.
javascript ๊ฐ์ฒด ํ‚ค ์ด๋ฆ„ ๋ณ€๊ฒฝ ๊ฐ์ฒด ํ‚ค ์ด๋ฆ„ ๋ณ€๊ฒฝํ•˜๊ธฐ (๊ฐ์ฒด ๋ฐฐ์—ด) map ์ธ์ž๋กœ ๊ฐ์ฒด๋ฅผ ๊ตฌ์กฐ๋ถ„ํ•ดํ•˜์—ฌ ๋‹ค๋ฅธ ์ด๋ฆ„์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ์ƒˆ๋กœ์šด ๊ฐ์ฒด๋กœ ๋ฆฌํ„ดํ•œ๋‹ค. let origins = [{ old1: 'origins[0].old1', old2: 'origins[0].old2', old3: 'origins[0].old3' }, { old1: 'origins[1].old1', old2: 'origins[1].old2', old3: 'origins[1].old3' }]; let results = origins.map(({ old1: new1, old2: new2, ...rest }) => ({ new1, new2, ...rest })); ๊ฐ์ฒด ํ‚ค ์ด๋ฆ„ ๋ณ€๊ฒฝํ•˜๊ธฐ (๊ฐ์ฒด) let origin = { old1: 'origins[0].old1', old2.. 2022. 7. 8.
javascript ๋ฐฐ์—ด ๋‚ด ์ค‘๋ณต ๊ฐ’ ๊ตฌํ•˜๊ธฐ ๋ฐฐ์—ด ๋‚ด์—์„œ ์ค‘๋ณต ๊ฐ’์„ ์ถ”์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด [1, 1, 2, 3, 5] ๋ฐฐ์—ด์—์„œ ์ค‘๋ณต ๊ฐ’์ธ [1] ์„ ๊ตฌํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ์ค‘๋ณต ๊ฐ’์„ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ๋Œ€์ƒ ๋ฐฐ์—ด์ด ๊ฐ์ฒด๋ฅผ ์š”์†Œ๋กœ ๊ฐ–๋Š” ๋ฐฐ์—ด์ด๋ผ๋ฉด ๊ฐ์ฒด์—์„œ ์ค‘๋ณต์„ ๊ฒ€์‚ฌํ•  ๋Œ€์ƒ๋งŒ ์ถ”์ถœํ•œ๋‹ค. (์ค‘๋ณต์ด ๊ฐ์ฒด ๋‚ด ๊ฐ’์ด ์•„๋‹ˆ๋ผ ๊ฐ์ฒด ์ž์ฒด๋ผ๋ฉด JSON.stringify() ๋“ฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค.) // ๋ฐ์ดํ„ฐ let arr = [{ "name": "ํ™๊ธธ๋™", "phoneNumber": "010-1111-1111" }, { "name": "๊น€๊ธธ๋™", "phoneNumber": "010-2222-2222" }, { "name": "๊ณ ๊ธธ๋™", "phoneNumber": "010-3333-3333" }, { "name": "์„œ๊ธธ๋™", "phoneNumber": ".. 2022. 6. 23.
javascript byte ์ˆ˜ ๊ณ„์‚ฐ euc-kr byte ๊ตฌํ•˜๊ธฐ ํ•œ๊ธ€ ํ•œ ๊ธ€์ž๋‹น 2byte ๊ธฐ์ค€ ๋ฐ”์ดํŠธ ์ˆ˜ ๊ณ„์‚ฐ function calcByteEuckr(str) { return str .split('') .map(s => s.charCodeAt(0))// ์œ ๋‹ˆ์ฝ”๋“œ ๊ฐ’์œผ๋กœ ๋ณ€ํ™˜ .reduce((prev, c) => (prev + ((c === 10) ? 2 : ((c >> 7) ? 2 : 1))), 0); // c ๊ฐ’์ด 0~127์‚ฌ์ด์— ์žˆ์œผ๋ฉด 1๋ฐ”์ดํŠธ } ์ตœ๋Œ€ byte ๋งŒํผ๋งŒ ๋ฌธ์ž์—ด ์ž๋ฅด๊ธฐ function getLimitedByteEuckrText(str, maxByte) { if (!str) return; let b; for (b = i = 0; (c = str.charCodeAt(i)); ) { b += (c === 10) ? 2 : .. 2022. 6. 21.
Vue.js xlsx ์—‘์…€ ๋‹ค์šด๋กœ๋“œ Vue ์—‘์…€ ๋‹ค์šด๋กœ๋“œ ์„œ๋ฒ„๋ฅผ ๊ฑฐ์น˜์ง€ ์•Š๊ณ  ํ™”๋ฉด ์ƒ์—์„œ xlsx ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด ์—‘์…€ ๋‹ค์šด๋กœ๋“œ๋ฅผ ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. xlsx ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜ npm install --save xlsx xlsx ๋ฅผ ์‚ฌ์šฉํ•œ ์—‘์…€ ๋‹ค์šด๋กœ๋“œ ๊ธฐ๋Šฅ ๊ตฌํ˜„ import xlsx from 'xlsx'; ... excelDownload() { const fileName = 'excelFile';// ํŒŒ์ผ๋ช… const sheetName = 'sheet1';// ์‹œํŠธ๋ช… const header = [['์ด๋ฆ„', '๋‚˜์ด', '์ด๋ฉ”์ผ']];// ์ปฌ๋Ÿผ๋ช… const list = [{ name: 'ํ™๊ธธ๋™', age: 15, email: 'ํ™๊ธธ๋™@naver.com' }, { name: '๊น€๊ธธ๋™', age: 44, email: '๊น€๊ธธ๋™@naver.com'.. 2022. 6. 16.