Я создал бэкэнд, используя команду npm generator-rest, в этом API, созданном npm автоматически .... после создания apis мы должны были отправить access_token со всем запросом, но когда операция удаления выполняется с access_token, это выдаст ошибку несанкционированного доступа.произошло
<!-- I have tried to send access_token like-->
var access_token="jQ4ykm5kgor54s6af2oV0sl"
deleteCountriesById(id) {
return this._http.delete("http://localhost:9000/countries/" + id,access_token)
.pipe(
map((res: Response) => {
return res.json();
})
);
}
нет опции для отправки access_token, тогда как методом post я отправлял токен доступа с данными, поэтому он работает, но здесь, в delete api, мы можем только отправить "id "для удаления.master () запрашивает токен доступа
///////// Requirements for method to be executed
/**
* @api {delete} /countries/:id Delete countries
* @apiName DeleteCountries
* @apiGroup Countries
* @apiPermission master
* @apiParam {String} access_token master access token. <---- Look here
* @apiSuccess (Success 204) 204 No Content.
* @apiError 404 Countries not found.
* @apiError 401 master access only.
*/
This is the auto created api ---->
router.delete('/:id',master(), destroy)
there is no option to send access_token , while post method i was sending access token incling with data that's why it is working, but here in delete api we can only send "id" for delete. master() is ask for an access_token
///////////////////////////////////////////////////////////////////////////////
example api for post method ------->
/**
* @api {post} /countries Create countries
* @apiName CreateCountries
* @apiGroup Countries
* @apiPermission master
* @apiParam {String} access_token master access token. <------- Look Here
* @apiParam country Countries's country.
* @apiParam iso_alpha2 Countries's iso_alpha2.
* @apiParam iso_alpha3 Countries's iso_alpha3.
* @apiParam iso_numeric Countries's iso_numeric.
* @apiParam country_code Countries's country_code.
* @apiParam currency_name Countries's currency_name.
* @apiParam currency_symbol Countries's currency_symbol.
* @apiParam flag Countries's flag.
* @apiParam status Countries's status.
* @apiParam created Countries's created.
* @apiParam modified Countries's modified.
* @apiSuccess {Object} countries Countries's data.
* @apiError {Object} 400 Some parameters may contain invalid values.
* @apiError 404 Countries not found.
* @apiError 401 master access only.
*/
router.post
('/', master(), body({ country,country_code, currency_name, currency symbol, flag}), create)
**strong text**
Я отправил access_token в то время как сообщение
// data contain form data with access_token variable with its value, acces_token will be get you when u created npm genrator-rest
addCountries(data) {
return this._http.post("http://localhost:9000/countries", data).pipe(
map((res: Response) => {
return res.json();
})
);
}