{"id":356,"date":"2025-02-20T14:22:48","date_gmt":"2025-02-20T07:22:48","guid":{"rendered":"https:\/\/tikky.xyz\/blog\/?p=356"},"modified":"2025-05-23T11:20:49","modified_gmt":"2025-05-23T04:20:49","slug":"rest-api-%e0%b9%81%e0%b8%99%e0%b8%a7%e0%b8%84%e0%b8%b4%e0%b8%94%e0%b9%81%e0%b8%a5%e0%b8%b0%e0%b8%95%e0%b8%b1%e0%b8%a7%e0%b8%ad%e0%b8%a2%e0%b9%88%e0%b8%b2%e0%b8%87%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%9e","status":"publish","type":"post","link":"https:\/\/tikky.xyz\/blog\/?p=356","title":{"rendered":"REST API &#8211; \u0e41\u0e19\u0e27\u0e04\u0e34\u0e14\u0e41\u0e25\u0e30\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e1e\u0e31\u0e12\u0e19\u0e32"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">REST API \u0e04\u0e37\u0e2d\u0e2d\u0e30\u0e44\u0e23?<\/h1>\n\n\n\n<p>REST (Representational State Transfer) \u0e40\u0e1b\u0e47\u0e19\u0e2a\u0e16\u0e32\u0e1b\u0e31\u0e15\u0e22\u0e01\u0e23\u0e23\u0e21\u0e01\u0e32\u0e23\u0e2d\u0e2d\u0e01\u0e41\u0e1a\u0e1a API \u0e17\u0e35\u0e48\u0e43\u0e0a\u0e49\u0e2b\u0e25\u0e31\u0e01\u0e01\u0e32\u0e23\u0e02\u0e2d\u0e07 HTTP protocol \u0e42\u0e14\u0e22\u0e21\u0e35\u0e2b\u0e25\u0e31\u0e01\u0e01\u0e32\u0e23\u0e2a\u0e33\u0e04\u0e31\u0e0d\u0e04\u0e37\u0e2d:<\/p>\n\n\n\n<ol>\n<li>Stateless &#8211; \u0e44\u0e21\u0e48\u0e40\u0e01\u0e47\u0e1a\u0e2a\u0e16\u0e32\u0e19\u0e30\u0e02\u0e2d\u0e07 client<\/li>\n\n\n\n<li>Client-Server Architecture &#8211; \u0e41\u0e22\u0e01\u0e01\u0e32\u0e23\u0e17\u0e33\u0e07\u0e32\u0e19\u0e23\u0e30\u0e2b\u0e27\u0e48\u0e32\u0e07 client \u0e41\u0e25\u0e30 server<\/li>\n\n\n\n<li>Cacheable &#8211; \u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16 cache \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e44\u0e14\u0e49<\/li>\n\n\n\n<li>Uniform Interface &#8211; \u0e43\u0e0a\u0e49\u0e23\u0e39\u0e1b\u0e41\u0e1a\u0e1a\u0e01\u0e32\u0e23\u0e40\u0e23\u0e35\u0e22\u0e01\u0e17\u0e35\u0e48\u0e40\u0e1b\u0e47\u0e19\u0e21\u0e32\u0e15\u0e23\u0e10\u0e32\u0e19<\/li>\n\n\n\n<li>Layered System &#8211; \u0e23\u0e30\u0e1a\u0e1a\u0e2a\u0e32\u0e21\u0e32\u0e23\u0e16\u0e21\u0e35\u0e2b\u0e25\u0e32\u0e22\u0e0a\u0e31\u0e49\u0e19<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">HTTP Methods \u0e17\u0e35\u0e48\u0e43\u0e0a\u0e49\u0e43\u0e19 REST API<\/h2>\n\n\n\n<ul>\n<li>GET &#8211; \u0e14\u0e36\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25<\/li>\n\n\n\n<li>POST &#8211; \u0e2a\u0e23\u0e49\u0e32\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e43\u0e2b\u0e21\u0e48<\/li>\n\n\n\n<li>PUT &#8211; \u0e2d\u0e31\u0e1e\u0e40\u0e14\u0e17\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e17\u0e31\u0e49\u0e07\u0e2b\u0e21\u0e14<\/li>\n\n\n\n<li>PATCH &#8211; \u0e2d\u0e31\u0e1e\u0e40\u0e14\u0e17\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e1a\u0e32\u0e07\u0e2a\u0e48\u0e27\u0e19<\/li>\n\n\n\n<li>DELETE &#8211; \u0e25\u0e1a\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e1e\u0e31\u0e12\u0e19\u0e32 REST API \u0e14\u0e49\u0e27\u0e22 PHP<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u0e01\u0e32\u0e23\u0e15\u0e31\u0e49\u0e07\u0e04\u0e48\u0e32\u0e40\u0e1a\u0e37\u0e49\u0e2d\u0e07\u0e15\u0e49\u0e19<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nheader(\"Content-Type: application\/json; charset=UTF-8\");\nheader(\"Access-Control-Allow-Methods: GET,POST,PUT,DELETE\");\nheader(\"Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With\");\n\n\/\/ \u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e15\u0e48\u0e2d\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\n$conn = new mysqli(\"localhost\", \"username\", \"password\", \"db_name\");<\/pre>\n\n\n\n<p>\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07 API Endpoints<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/ GET \/api\/users - \u0e14\u0e36\u0e07\u0e23\u0e32\u0e22\u0e01\u0e32\u0e23\u0e1c\u0e39\u0e49\u0e43\u0e0a\u0e49\u0e17\u0e31\u0e49\u0e07\u0e2b\u0e21\u0e14\nif ($_SERVER['REQUEST_METHOD'] === 'GET') {\n    $sql = \"SELECT * FROM users\";\n    $result = $conn->query($sql);\n    $users = [];\n    \n    while($row = $result->fetch_assoc()) {\n        $users[] = $row;\n    }\n    \n    echo json_encode(['status' => 'success', 'data' => $users]);\n}\n\n\/\/ POST \/api\/users - \u0e2a\u0e23\u0e49\u0e32\u0e07\u0e1c\u0e39\u0e49\u0e43\u0e0a\u0e49\u0e43\u0e2b\u0e21\u0e48\nif ($_SERVER['REQUEST_METHOD'] === 'POST') {\n    $data = json_decode(file_get_contents(\"php:\/\/input\"));\n    \n    $sql = \"INSERT INTO users (name, email) VALUES (?, ?)\";\n    $stmt = $conn->prepare($sql);\n    $stmt->bind_param(\"ss\", $data->name, $data->email);\n    \n    if ($stmt->execute()) {\n        echo json_encode(['status' => 'success', 'message' => 'User created']);\n    } else {\n        echo json_encode(['status' => 'error', 'message' => $conn->error]);\n    }\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e1e\u0e31\u0e12\u0e19\u0e32 REST API \u0e14\u0e49\u0e27\u0e22 Node.js \u0e41\u0e25\u0e30 Express<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u0e01\u0e32\u0e23\u0e15\u0e31\u0e49\u0e07\u0e04\u0e48\u0e32\u0e40\u0e1a\u0e37\u0e49\u0e2d\u0e07\u0e15\u0e49\u0e19<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const express = require('express');\nconst bodyParser = require('body-parser');\nconst app = express();\n\napp.use(bodyParser.json());\n\n\/\/ \u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e15\u0e48\u0e2d MongoDB \u0e14\u0e49\u0e27\u0e22 Mongoose\nconst mongoose = require('mongoose');\nmongoose.connect('mongodb:\/\/localhost\/api_db', { useNewUrlParser: true });<\/pre>\n\n\n\n<p>\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07 Model<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">const userSchema = new mongoose.Schema({\n    name: String,\n    email: String,\n    createdAt: { type: Date, default: Date.now }\n});\n\nconst User = mongoose.model('User', userSchema);<\/pre>\n\n\n\n<p>\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07 API Routes<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ GET \/api\/users - \u0e14\u0e36\u0e07\u0e23\u0e32\u0e22\u0e01\u0e32\u0e23\u0e1c\u0e39\u0e49\u0e43\u0e0a\u0e49\u0e17\u0e31\u0e49\u0e07\u0e2b\u0e21\u0e14\napp.get('\/api\/users', async (req, res) => {\n    try {\n        const users = await User.find();\n        res.json({ status: 'success', data: users });\n    } catch (err) {\n        res.status(500).json({ status: 'error', message: err.message });\n    }\n});\n\n\/\/ POST \/api\/users - \u0e2a\u0e23\u0e49\u0e32\u0e07\u0e1c\u0e39\u0e49\u0e43\u0e0a\u0e49\u0e43\u0e2b\u0e21\u0e48\napp.post('\/api\/users', async (req, res) => {\n    try {\n        const user = new User({\n            name: req.body.name,\n            email: req.body.email\n        });\n        \n        const newUser = await user.save();\n        res.status(201).json({ status: 'success', data: newUser });\n    } catch (err) {\n        res.status(400).json({ status: 'error', message: err.message });\n    }\n});\n\n\/\/ PUT \/api\/users\/:id - \u0e2d\u0e31\u0e1e\u0e40\u0e14\u0e17\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e1c\u0e39\u0e49\u0e43\u0e0a\u0e49\napp.put('\/api\/users\/:id', async (req, res) => {\n    try {\n        const user = await User.findByIdAndUpdate(\n            req.params.id,\n            req.body,\n            { new: true }\n        );\n        res.json({ status: 'success', data: user });\n    } catch (err) {\n        res.status(400).json({ status: 'error', message: err.message });\n    }\n});\n\n\/\/ DELETE \/api\/users\/:id - \u0e25\u0e1a\u0e1c\u0e39\u0e49\u0e43\u0e0a\u0e49\napp.delete('\/api\/users\/:id', async (req, res) => {\n    try {\n        await User.findByIdAndDelete(req.params.id);\n        res.json({ status: 'success', message: 'User deleted' });\n    } catch (err) {\n        res.status(500).json({ status: 'error', message: err.message });\n    }\n});<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u0e41\u0e19\u0e27\u0e17\u0e32\u0e07\u0e01\u0e32\u0e23\u0e1e\u0e31\u0e12\u0e19\u0e32 REST API \u0e17\u0e35\u0e48\u0e14\u0e35<\/h2>\n\n\n\n<ol>\n<li>\u0e01\u0e32\u0e23\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23 Response<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e23\u0e39\u0e1b\u0e41\u0e1a\u0e1a Response \u0e17\u0e35\u0e48\u0e14\u0e35\n{\n    \"status\": \"success\",\n    \"data\": {\n        \"id\": 1,\n        \"name\": \"John Doe\",\n        \"email\": \"john@example.com\"\n    },\n    \"message\": \"User created successfully\"\n}<\/pre>\n\n\n\n<p>2. \u0e01\u0e32\u0e23\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23 Error<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e23\u0e39\u0e1b\u0e41\u0e1a\u0e1a Error Response\n{\n    \"status\": \"error\",\n    \"code\": 400,\n    \"message\": \"Invalid email format\",\n    \"errors\": [\n        {\n            \"field\": \"email\",\n            \"message\": \"Email is not valid\"\n        }\n    ]\n}<\/pre>\n\n\n\n<ol start=\"3\">\n<li>\u0e01\u0e32\u0e23\u0e15\u0e31\u0e49\u0e07\u0e0a\u0e37\u0e48\u0e2d Endpoints<\/li>\n<\/ol>\n\n\n\n<ul>\n<li>\u0e43\u0e0a\u0e49\u0e04\u0e33\u0e19\u0e32\u0e21 \u0e41\u0e17\u0e19\u0e04\u0e33\u0e01\u0e23\u0e34\u0e22\u0e32: <code>\/api\/users<\/code> \u0e41\u0e17\u0e19 <code>\/api\/getUsers<\/code><\/li>\n\n\n\n<li>\u0e43\u0e0a\u0e49\u0e15\u0e31\u0e27\u0e1e\u0e34\u0e21\u0e1e\u0e4c\u0e40\u0e25\u0e47\u0e01\u0e17\u0e31\u0e49\u0e07\u0e2b\u0e21\u0e14<\/li>\n\n\n\n<li>\u0e43\u0e0a\u0e49\u0e02\u0e35\u0e14\u0e01\u0e25\u0e32\u0e07\u0e43\u0e19\u0e01\u0e32\u0e23\u0e41\u0e1a\u0e48\u0e07\u0e04\u0e33: <code>\/api\/user-profiles<\/code><\/li>\n<\/ul>\n\n\n\n<ol start=\"4\">\n<li>\u0e01\u0e32\u0e23\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23 Version<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/api\/v1\/users\n\/api\/v2\/users<\/pre>\n\n\n\n<ol start=\"5\">\n<li>\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49 HTTP Status Codes \u0e17\u0e35\u0e48\u0e40\u0e2b\u0e21\u0e32\u0e30\u0e2a\u0e21<\/li>\n<\/ol>\n\n\n\n<ul>\n<li>200 OK &#8211; \u0e2a\u0e33\u0e40\u0e23\u0e47\u0e08<\/li>\n\n\n\n<li>201 Created &#8211; \u0e2a\u0e23\u0e49\u0e32\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e2a\u0e33\u0e40\u0e23\u0e47\u0e08<\/li>\n\n\n\n<li>400 Bad Request &#8211; \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e44\u0e21\u0e48\u0e16\u0e39\u0e01\u0e15\u0e49\u0e2d\u0e07<\/li>\n\n\n\n<li>401 Unauthorized &#8211; \u0e44\u0e21\u0e48\u0e44\u0e14\u0e49\u0e22\u0e37\u0e19\u0e22\u0e31\u0e19\u0e15\u0e31\u0e27\u0e15\u0e19<\/li>\n\n\n\n<li>403 Forbidden &#8211; \u0e44\u0e21\u0e48\u0e21\u0e35\u0e2a\u0e34\u0e17\u0e18\u0e34\u0e4c<\/li>\n\n\n\n<li>404 Not Found &#8211; \u0e44\u0e21\u0e48\u0e1e\u0e1a\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25<\/li>\n\n\n\n<li>500 Internal Server Error &#8211; \u0e40\u0e01\u0e34\u0e14\u0e02\u0e49\u0e2d\u0e1c\u0e34\u0e14\u0e1e\u0e25\u0e32\u0e14\u0e17\u0e35\u0e48\u0e40\u0e0b\u0e34\u0e23\u0e4c\u0e1f\u0e40\u0e27\u0e2d\u0e23\u0e4c<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u0e01\u0e32\u0e23\u0e23\u0e31\u0e01\u0e29\u0e32\u0e04\u0e27\u0e32\u0e21\u0e1b\u0e25\u0e2d\u0e14\u0e20\u0e31\u0e22<\/h2>\n\n\n\n<ol>\n<li>\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49 JWT (JSON Web Tokens)<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Node.js example\nconst jwt = require('jsonwebtoken');\n\n\/\/ \u0e2a\u0e23\u0e49\u0e32\u0e07 token\nconst token = jwt.sign({ userId: user.id }, 'secret_key', { expiresIn: '1h' });\n\n\/\/ \u0e15\u0e23\u0e27\u0e08\u0e2a\u0e2d\u0e1a token\nconst verifyToken = (req, res, next) => {\n    const token = req.headers.authorization;\n    if (!token) return res.status(401).json({ message: 'Token required' });\n\n    try {\n        const decoded = jwt.verify(token, 'secret_key');\n        req.user = decoded;\n        next();\n    } catch (err) {\n        res.status(401).json({ message: 'Invalid token' });\n    }\n};<\/pre>\n\n\n\n<ol start=\"2\">\n<li>\u0e01\u0e32\u0e23\u0e1b\u0e49\u0e2d\u0e07\u0e01\u0e31\u0e19 SQL Injection<\/li>\n<\/ol>\n\n\n\n<ul>\n<li>\u0e43\u0e0a\u0e49 Prepared Statements<\/li>\n\n\n\n<li>\u0e43\u0e0a\u0e49 ORM<\/li>\n\n\n\n<li>Sanitize \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 input<\/li>\n<\/ul>\n\n\n\n<ol start=\"3\">\n<li>\u0e01\u0e32\u0e23\u0e08\u0e33\u0e01\u0e31\u0e14 Rate Limiting<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Node.js example using express-rate-limit\nconst rateLimit = require('express-rate-limit');\n\nconst limiter = rateLimit({\n    windowMs: 15 * 60 * 1000, \/\/ 15 \u0e19\u0e32\u0e17\u0e35\n    max: 100 \/\/ \u0e08\u0e33\u0e01\u0e31\u0e14 100 requests \u0e15\u0e48\u0e2d IP\n});\n\napp.use('\/api\/', limiter);<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u0e01\u0e32\u0e23\u0e17\u0e14\u0e2a\u0e2d\u0e1a API<\/h2>\n\n\n\n<ol>\n<li>\u0e43\u0e0a\u0e49\u0e40\u0e04\u0e23\u0e37\u0e48\u0e2d\u0e07\u0e21\u0e37\u0e2d\u0e17\u0e14\u0e2a\u0e2d\u0e1a<\/li>\n<\/ol>\n\n\n\n<ul>\n<li>Postman<\/li>\n\n\n\n<li>curl<\/li>\n\n\n\n<li>Jest (\u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a Node.js)<\/li>\n\n\n\n<li>PHPUnit (\u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a PHP)<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\">\n<li>\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e17\u0e14\u0e2a\u0e2d\u0e1a\u0e14\u0e49\u0e27\u0e22 Jest<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">describe('User API', () => {\n    test('should create a new user', async () => {\n        const res = await request(app)\n            .post('\/api\/users')\n            .send({\n                name: 'Test User',\n                email: 'test@example.com'\n            });\n        \n        expect(res.statusCode).toBe(201);\n        expect(res.body.data).toHaveProperty('name', 'Test User');\n    });\n});<\/pre>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_356\" class=\"pvc_stats all  \" data-element-id=\"356\" style=\"\"><i class=\"pvc-stats-icon small\" aria-hidden=\"true\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.0\" viewBox=\"0 0 502 315\" preserveAspectRatio=\"xMidYMid meet\"><g transform=\"translate(0,332) scale(0.1,-0.1)\" fill=\"\" stroke=\"none\"><path d=\"M2394 3279 l-29 -30 -3 -207 c-2 -182 0 -211 15 -242 39 -76 157 -76 196 0 15 31 17 60 15 243 l-3 209 -33 29 c-26 23 -41 29 -80 29 -41 0 -53 -5 -78 -31z\"\/><path d=\"M3085 3251 c-45 -19 -58 -50 -96 -229 -47 -217 -49 -260 -13 -295 52 -53 146 -42 177 20 16 31 87 366 87 410 0 70 -86 122 -155 94z\"\/><path d=\"M1751 3234 c-13 -9 -29 -31 -37 -50 -12 -29 -10 -49 21 -204 19 -94 39 -189 45 -210 14 -50 54 -80 110 -80 34 0 48 6 76 34 21 21 34 44 34 59 0 14 -18 113 -40 219 -37 178 -43 195 -70 221 -36 32 -101 37 -139 11z\"\/><path d=\"M1163 3073 c-36 -7 -73 -59 -73 -102 0 -56 133 -378 171 -413 34 -32 83 -37 129 -13 70 36 67 87 -16 290 -86 209 -89 214 -129 231 -35 14 -42 15 -82 7z\"\/><path d=\"M3689 3066 c-15 -9 -33 -30 -42 -48 -48 -103 -147 -355 -147 -375 0 -98 131 -148 192 -74 13 15 57 108 97 206 80 196 84 226 37 273 -30 30 -99 39 -137 18z\"\/><path d=\"M583 2784 c-38 -19 -67 -74 -58 -113 9 -42 211 -354 242 -373 16 -10 45 -18 66 -18 51 0 107 52 107 100 0 39 -1 41 -124 234 -80 126 -108 162 -133 173 -41 17 -61 16 -100 -3z\"\/><path d=\"M4250 2784 c-14 -9 -74 -91 -133 -183 -95 -150 -107 -173 -107 -213 0 -55 33 -94 87 -104 67 -13 90 8 211 198 130 202 137 225 78 284 -27 27 -42 34 -72 34 -22 0 -50 -8 -64 -16z\"\/><path d=\"M2275 2693 c-553 -48 -1095 -270 -1585 -649 -135 -104 -459 -423 -483 -476 -23 -49 -22 -139 2 -186 73 -142 361 -457 571 -626 285 -228 642 -407 990 -497 242 -63 336 -73 660 -74 310 0 370 5 595 52 535 111 1045 392 1455 803 122 121 250 273 275 326 19 41 19 137 0 174 -41 79 -309 363 -465 492 -447 370 -946 591 -1479 653 -113 14 -422 18 -536 8z m395 -428 c171 -34 330 -124 456 -258 112 -119 167 -219 211 -378 27 -96 24 -300 -5 -401 -72 -255 -236 -447 -474 -557 -132 -62 -201 -76 -368 -76 -167 0 -236 14 -368 76 -213 98 -373 271 -451 485 -162 444 86 934 547 1084 153 49 292 57 452 25z m909 -232 c222 -123 408 -262 593 -441 76 -74 138 -139 138 -144 0 -16 -233 -242 -330 -319 -155 -123 -309 -223 -461 -299 l-81 -41 32 46 c18 26 49 83 70 128 143 306 141 649 -6 957 -25 52 -61 116 -79 142 l-34 47 45 -20 c26 -10 76 -36 113 -56z m-2057 25 c-40 -58 -105 -190 -130 -263 -110 -324 -59 -707 132 -981 25 -35 42 -64 37 -64 -19 0 -241 119 -326 174 -188 122 -406 314 -532 468 l-58 71 108 103 c185 178 428 349 672 473 66 33 121 60 123 61 2 0 -10 -19 -26 -42z\"\/><path d=\"M2375 1950 c-198 -44 -350 -190 -395 -379 -18 -76 -8 -221 19 -290 114 -284 457 -406 731 -260 98 52 188 154 231 260 27 69 37 214 19 290 -38 163 -166 304 -326 360 -67 23 -215 33 -279 19z\"\/><\/g><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/tikky.xyz\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>REST API \u0e04\u0e37\u0e2d\u0e2d\u0e30\u0e44\u0e23? REST (Representational State Transfer) \u0e40\u0e1b\u0e47\u0e19\u0e2a\u0e16\u0e32\u0e1b\u0e31\u0e15\u0e22\u0e01\u0e23\u0e23\u0e21\u0e01\u0e32\u0e23\u0e2d\u0e2d\u0e01\u0e41\u0e1a\u0e1a API \u0e17\u0e35\u0e48\u0e43\u0e0a\u0e49\u0e2b\u0e25\u0e31\u0e01\u0e01\u0e32\u0e23\u0e02\u0e2d\u0e07 HTTP protocol \u0e42\u0e14\u0e22\u0e21\u0e35\u0e2b\u0e25\u0e31\u0e01\u0e01\u0e32\u0e23\u0e2a\u0e33\u0e04\u0e31\u0e0d\u0e04\u0e37\u0e2d: HTTP Methods \u0e17\u0e35\u0e48\u0e43\u0e0a\u0e49\u0e43\u0e19 REST API \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e1e\u0e31\u0e12\u0e19\u0e32 REST API \u0e14\u0e49\u0e27\u0e22 PHP \u0e01\u0e32\u0e23\u0e15\u0e31\u0e49\u0e07\u0e04\u0e48\u0e32\u0e40\u0e1a\u0e37\u0e49\u0e2d\u0e07\u0e15\u0e49\u0e19 \u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07 API Endpoints \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e1e\u0e31\u0e12\u0e19\u0e32 REST API \u0e14\u0e49\u0e27\u0e22 Node.js \u0e41\u0e25\u0e30 Express \u0e01\u0e32\u0e23\u0e15\u0e31\u0e49\u0e07\u0e04\u0e48\u0e32\u0e40\u0e1a\u0e37\u0e49\u0e2d\u0e07\u0e15\u0e49\u0e19 \u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07 Model \u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07 API Routes \u0e41\u0e19\u0e27\u0e17\u0e32\u0e07\u0e01\u0e32\u0e23\u0e1e\u0e31\u0e12\u0e19\u0e32 REST API \u0e17\u0e35\u0e48\u0e14\u0e35 2. \u0e01\u0e32\u0e23\u0e08\u0e31\u0e14\u0e01\u0e32\u0e23 Error \u0e01\u0e32\u0e23\u0e23\u0e31\u0e01\u0e29\u0e32\u0e04\u0e27\u0e32\u0e21\u0e1b\u0e25\u0e2d\u0e14\u0e20\u0e31\u0e22 \u0e01\u0e32\u0e23\u0e17\u0e14\u0e2a\u0e2d\u0e1a API<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_356\" class=\"pvc_stats all  \" data-element-id=\"356\" style=\"\"><i class=\"pvc-stats-icon small\" aria-hidden=\"true\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.0\" viewBox=\"0 0 502 315\" preserveAspectRatio=\"xMidYMid meet\"><g transform=\"translate(0,332) scale(0.1,-0.1)\" fill=\"\" stroke=\"none\"><path d=\"M2394 3279 l-29 -30 -3 -207 c-2 -182 0 -211 15 -242 39 -76 157 -76 196 0 15 31 17 60 15 243 l-3 209 -33 29 c-26 23 -41 29 -80 29 -41 0 -53 -5 -78 -31z\"\/><path d=\"M3085 3251 c-45 -19 -58 -50 -96 -229 -47 -217 -49 -260 -13 -295 52 -53 146 -42 177 20 16 31 87 366 87 410 0 70 -86 122 -155 94z\"\/><path d=\"M1751 3234 c-13 -9 -29 -31 -37 -50 -12 -29 -10 -49 21 -204 19 -94 39 -189 45 -210 14 -50 54 -80 110 -80 34 0 48 6 76 34 21 21 34 44 34 59 0 14 -18 113 -40 219 -37 178 -43 195 -70 221 -36 32 -101 37 -139 11z\"\/><path d=\"M1163 3073 c-36 -7 -73 -59 -73 -102 0 -56 133 -378 171 -413 34 -32 83 -37 129 -13 70 36 67 87 -16 290 -86 209 -89 214 -129 231 -35 14 -42 15 -82 7z\"\/><path d=\"M3689 3066 c-15 -9 -33 -30 -42 -48 -48 -103 -147 -355 -147 -375 0 -98 131 -148 192 -74 13 15 57 108 97 206 80 196 84 226 37 273 -30 30 -99 39 -137 18z\"\/><path d=\"M583 2784 c-38 -19 -67 -74 -58 -113 9 -42 211 -354 242 -373 16 -10 45 -18 66 -18 51 0 107 52 107 100 0 39 -1 41 -124 234 -80 126 -108 162 -133 173 -41 17 -61 16 -100 -3z\"\/><path d=\"M4250 2784 c-14 -9 -74 -91 -133 -183 -95 -150 -107 -173 -107 -213 0 -55 33 -94 87 -104 67 -13 90 8 211 198 130 202 137 225 78 284 -27 27 -42 34 -72 34 -22 0 -50 -8 -64 -16z\"\/><path d=\"M2275 2693 c-553 -48 -1095 -270 -1585 -649 -135 -104 -459 -423 -483 -476 -23 -49 -22 -139 2 -186 73 -142 361 -457 571 -626 285 -228 642 -407 990 -497 242 -63 336 -73 660 -74 310 0 370 5 595 52 535 111 1045 392 1455 803 122 121 250 273 275 326 19 41 19 137 0 174 -41 79 -309 363 -465 492 -447 370 -946 591 -1479 653 -113 14 -422 18 -536 8z m395 -428 c171 -34 330 -124 456 -258 112 -119 167 -219 211 -378 27 -96 24 -300 -5 -401 -72 -255 -236 -447 -474 -557 -132 -62 -201 -76 -368 -76 -167 0 -236 14 -368 76 -213 98 -373 271 -451 485 -162 444 86 934 547 1084 153 49 292 57 452 25z m909 -232 c222 -123 408 -262 593 -441 76 -74 138 -139 138 -144 0 -16 -233 -242 -330 -319 -155 -123 -309 -223 -461 -299 l-81 -41 32 46 c18 26 49 83 70 128 143 306 141 649 -6 957 -25 52 -61 116 -79 142 l-34 47 45 -20 c26 -10 76 -36 113 -56z m-2057 25 c-40 -58 -105 -190 -130 -263 -110 -324 -59 -707 132 -981 25 -35 42 -64 37 -64 -19 0 -241 119 -326 174 -188 122 -406 314 -532 468 l-58 71 108 103 c185 178 428 349 672 473 66 33 121 60 123 61 2 0 -10 -19 -26 -42z\"\/><path d=\"M2375 1950 c-198 -44 -350 -190 -395 -379 -18 -76 -8 -221 19 -290 114 -284 457 -406 731 -260 98 52 188 154 231 260 27 69 37 214 19 290 -38 163 -166 304 -326 360 -67 23 -215 33 -279 19z\"\/><\/g><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/tikky.xyz\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":359,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,11,7],"tags":[],"_links":{"self":[{"href":"https:\/\/tikky.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts\/356"}],"collection":[{"href":"https:\/\/tikky.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tikky.xyz\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tikky.xyz\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tikky.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356"}],"version-history":[{"count":3,"href":"https:\/\/tikky.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions"}],"predecessor-version":[{"id":361,"href":"https:\/\/tikky.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions\/361"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tikky.xyz\/blog\/index.php?rest_route=\/wp\/v2\/media\/359"}],"wp:attachment":[{"href":"https:\/\/tikky.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tikky.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tikky.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}