Designing Web Apis With Strapi Pdf Free Download Extra Quality [ 100% EXTENDED ]
mutation createArticle(data: title: "New API", content: "..." ) data id
Custom route: POST /api/orders/checkout Custom controller logic: designing web apis with strapi pdf free download
async checkout(ctx) const products, userId = ctx.request.body; const total = await strapi.service('api::order.calc').compute(products); return strapi.entityService.create('api::order.order', data: products, total, user: userId, status: 'pending' ); mutation createArticle(data: title: "New API", content: "
// src/api/article/policies/isOwner.js module.exports = (policyCtx) => if (policyCtx.state.user.id === policyCtx.request.body.data.user) return true; return false; ; Strapi auto-generates a GraphQL schema from your content-types. Setup npm run strapi install graphql Query example query articles(filters: title: contains: "Strapi" ) data id attributes title content author data attributes username mutation createArticle(data: title: "New API"
GET /api/articles?fields[0]=title&fields[1]=slug Control relation depth:
GET /api/articles?filters[title][$contains]=strapi GET /api/articles?sort=publishedAt:desc GET /api/articles?pagination[page]=1&pagination[pageSize]=10 GET /api/articles?populate=author,categories Return only needed fields:
// src/api/article/controllers/article.js module.exports = async find(ctx) ctx.query = ...ctx.query, populate: 'author' ; return await strapi.entityService.findMany('api::article.article', ctx.query); ; Use content-type validators or custom policies: