JSON in GET request: REST API

I am creating a very simple toy API that will take a list of People objects (passed as JSON), do some business logic based on their name and age, then return a response object based on the info provided. Input example: [ { "firstName": "John", "lastName": "Smith", "age": 45, "favoriteFood": "pizza" }, { "firstName": "Jane",… Read More JSON in GET request: REST API

Should a RESTful API return a 200 OK response when requesting a list of posts for a category that does not exist?

So, I have an RESTful API on a blog site (WordPress, but that’s irrelevant). I understand that if, for example, there are 0 posts in the category news, the route /posts/by-category/news/?limit=100&offset=0 should return a 200 OK response with a body like {total: 0, items: []}, which is quite logical. But what if the category news… Read More Should a RESTful API return a 200 OK response when requesting a list of posts for a category that does not exist?

Cannot GET error message showing using Rest Api in Nodejs

I am working with nodejs and using expressjs framework,Right now i am trying to run "Rest Api" but i am getting following error Cannot GET /published Here is my routes file module.exports = app => { const tutorials = require("../controllers/tutorial.controller.js"); var router = require("express").Router(); router.get("/published", tutorials.findAllPublished); }; Here is my controller exports.findAllPublished = (req, res)… Read More Cannot GET error message showing using Rest Api in Nodejs

How can I pass multiple Parameters in Node.JS with &

I want to do this in Node.JS I want to have a link like this, it should be a GET Request http://localhost:3000/api/bal/update-balance?email=aa@email.com&amount=4500 How can I do this in Node.JS My code is looking Thus const router = require("express").Router(); const User = require("../models/User"); const Trans = require("../models/Transactions"); const bcrypt = require("bcrypt"); const jwt = require("jsonwebtoken"); router.post("/update-balance",… Read More How can I pass multiple Parameters in Node.JS with &

Java post request with nested objects

I have an object Order which contains another object Person among other properties. I’m wondering what is the best solution to create an order through a post request. The first approach in my mind is something like this: @PostMapping("orders/create") public void createOrder(@RequestBody Order order) { orderRepository.save(order); } but what I don’t like about this solution… Read More Java post request with nested objects

React JS calling delete API with request body

My Delete API is http://localhost:8080/api/inventory/deleteproduct with the request body in JSON format: { "upc": "100101101111" } upc is the unique value for each product. Here is my code for fetching data from API: export function Inventory() { const [product, setProduct] = useState(null); useEffect(() => { axios .get("http://localhost:8080/api/inventory/products") .then((response) => { setProduct(response.data); }); }, [url]); if… Read More React JS calling delete API with request body