Category : rest

I’ve made a webapp for a simple marketplace. I have three different functions: searching, filtering, filtering by keys. Each of these functions contains different query parameters. My problem is that how should I separate these endpoints in a rest way? For example, this is my endpoint for searching: API.get(‘/product/’,{params:querydata}) On search I get these query ..

Read more

Im using a chrome extension with the following background.js to call the GMail API users.history.list method: chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) { if (changeInfo.status == ‘complete’) { chrome.identity.getAuthToken({ ‘interactive’: true }, function(token) { thisToken = token chrome.runtime.onMessage.addListener( function(request,sender,sendResponse){ var userlist = "https://gmail.googleapis.com/gmail/v1/users/me/history?startHistoryId=<historyId>&access_token=" + thisToken var makeGetRequest = function (gapiRequestURL) { var xmlHttp = new XMLHttpRequest(); ..

Read more

I use supertest, chai and mocha to run api-testing. I have the following code: app.js app.get(‘/post’, async (req, res, next) => { await postModel.find(); console.log("co xuong duoi la duoc"); res.json({loi: "hi"}).status(200) // postModel.find(() => res.json({loi: "hi"}).status(200)); //; }) test.js describe(‘GET /post’, () => { before(() => { db.connect() // .then(() => done()) // .catch((err) => ..

Read more

Im trying to learn REST API and got stuck with decoding data from JS FormData using PUT for example JS: newF = async (e) => { let formData = new FormData(); formData.append(‘key1’, ‘value1’); formData.append(‘key2’, ‘value2’); let response = await fetch(api, { method: ‘PUT’, body: formData }); let result = await response.json(); console.log(result) } newF() PHP: ..

Read more

Instead of calling a REST API on a server, make a rest call to a react js component. For Example: Call import React from ‘react’; function Post(props) { function fetchPost() { fetch(`http://localhost:3000/fetch_post/${props.match.params.post_id}`, { method: "GET", } ) .then((res) => { if (!res.ok) { return res.json().then(e => Promise.reject(e)); } return res.json(); }) .then((res) => { console.log(‘returned: ..

Read more