|
@@ -7,7 +7,7 @@ An API Route is created in a TypeScript or JavaScript file under the `/src/api`
|
|
|
For example, to create a `GET` API Route at `/store/hello-world`, create the file `src/api/store/hello-world/route.ts` with the following content:
|
|
|
|
|
|
```ts
|
|
|
-import type { MedusaRequest, MedusaResponse } from "@medusajs/framework";
|
|
|
+import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
|
|
|
|
|
|
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
|
res.json({
|
|
@@ -33,7 +33,7 @@ You can define a handler for each of these methods by exporting a function with
|
|
|
For example:
|
|
|
|
|
|
```ts
|
|
|
-import type { MedusaRequest, MedusaResponse } from "@medusajs/framework";
|
|
|
+import type { MedusaRequest, MedusaResponse } from "@medusajs/framework/http";
|
|
|
|
|
|
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
|
// Handle GET requests
|
|
@@ -58,7 +58,7 @@ For example, if you want to define a route that takes a `productId` parameter, y
|
|
|
import type {
|
|
|
MedusaRequest,
|
|
|
MedusaResponse,
|
|
|
-} from "@medusajs/framework"
|
|
|
+} from "@medusajs/framework/http"
|
|
|
|
|
|
export async function GET(req: MedusaRequest, res: MedusaResponse) {
|
|
|
const { productId } = req.params;
|
|
@@ -81,15 +81,14 @@ The Medusa container is available on `req.scope`. Use it to access modules' main
|
|
|
import type {
|
|
|
MedusaRequest,
|
|
|
MedusaResponse,
|
|
|
-} from "@medusajs/framework"
|
|
|
-import { IProductModuleService } from "@medusajs/framework/types"
|
|
|
+} from "@medusajs/framework/http"
|
|
|
import { Modules } from "@medusajs/framework/utils"
|
|
|
|
|
|
export const GET = async (
|
|
|
req: MedusaRequest,
|
|
|
res: MedusaResponse
|
|
|
) => {
|
|
|
- const productModuleService: IProductModuleService =
|
|
|
+ const productModuleService =
|
|
|
req.scope.resolve(Modules.PRODUCT)
|
|
|
|
|
|
const [, count] = await productModuleService.listAndCount()
|
|
@@ -107,12 +106,12 @@ You can apply middleware to your routes by creating a file called `/api/middlewa
|
|
|
For example, if you want to apply a custom middleware function to the `/store/custom` route, you can do so by adding the following to your `/api/middlewares.ts` file:
|
|
|
|
|
|
```ts
|
|
|
-import { defineMiddlewares } from "@medusajs/medusa"
|
|
|
+import { defineMiddlewares } from "@medusajs/framework/http"
|
|
|
import type {
|
|
|
MedusaRequest,
|
|
|
MedusaResponse,
|
|
|
MedusaNextFunction,
|
|
|
-} from "@medusajs/framework";
|
|
|
+} from "@medusajs/framework/http";
|
|
|
|
|
|
async function logger(
|
|
|
req: MedusaRequest,
|