我想使用邮递员将GET或POST之类的请求发送到nodejs应用程序的REST API。
例如,要获取该应用程序的用户,我进行了一次GET操作,必须像/ v1 / users一样写url,但返回的404找不到。
文件src / v1 / users / auth / routes.js的代码:
'use strict'
import { Router } from 'express'
import { middleware } from 'express-asyncable'
import x from 'throw-if-missing'
import AuthAttemptLocker from '../../../../request/authAttemptLocker'
const router = Router({ mergeParams: true })
export default function authRouter({
authController = x`authController`,
}: {
authController: Object
}): express$Router<express$Request, express$Response> {
const authAttemptLocker = new AuthAttemptLocker()
// Auth management
router.post(
'/auth',
middleware(authAttemptLocker.middleware.bind(authAttemptLocker)),
middleware(authController.auth.bind(authController))
)
router.post(
'/guest',
middleware(authController.guest.bind(authController))
)
if (process.env.ACTIVATE_GOOGLE_AUTH === '1') {
router.get(
'/auth/googlecallback',
middleware(authController.googleCallback.bind(authController))
)
}
if (process.env.ACTIVATE_REGISTRATION === '1') {
router.post(
'/register',
middleware(authController.register.bind(authController))
)
router.get(
'/activate/:hash',
middleware(authController.activate.bind(authController))
)
}
return router
}
答案 0 :(得分:1)
您正在使用完整域吗?
http://localhost:{port}/v1/users
您还可以通过直接转到浏览器中的网址来测试GET请求