mirror of
https://github.com/strapi/strapi.git
synced 2025-09-04 14:23:03 +00:00
1 line
36 KiB
JavaScript
1 line
36 KiB
JavaScript
![]() |
(window.webpackJsonp=window.webpackJsonp||[]).push([[6],{233:function(t,s,a){"use strict";a.r(s);var n=a(0),e=Object(n.a)({},function(){this.$createElement;this._self._c;return this._m(0)},[function(){var t=this,s=t.$createElement,a=t._self._c||s;return a("div",{staticClass:"content"},[a("h1",{attrs:{id:"blueprints"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#blueprints","aria-hidden":"true"}},[t._v("#")]),t._v(" Blueprints")]),t._v(" "),a("p",[t._v("The blueprints are a set of useful actions containing all the logic you need to\ncreate a clean RESTful API. The generated controllers and routes are automatically\nplugged to the blueprint actions. Thanks to that, as soon as you generate a new API\nfrom the CLI, you can enjoy a RESTful API without writing any line of code.")]),t._v(" "),a("p",[t._v("For example, if you generate a "),a("code",[t._v("pet")]),t._v(" API, you will be able to immediately visit\n"),a("code",[t._v("POST /pet?name=joe")]),t._v(" to create a pet, and visit "),a("code",[t._v("GET /pet")]),t._v(" to see an array\nof your application's pets.")]),t._v(" "),a("p",[t._v("Blueprints are great for prototyping, but they are also a powerful tool in production\ndue to their ability to be overridden, protected, extended or disabled entirely.")]),t._v(" "),a("p",[t._v("All of the following actions return a promise.")]),t._v(" "),a("h2",{attrs:{id:"find-records"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#find-records","aria-hidden":"true"}},[t._v("#")]),t._v(" find records")]),t._v(" "),a("p",[t._v("Returns a list of records from the model as a JSON array of objects.")]),t._v(" "),a("p",[t._v("Route:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"routes"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"GET /pet"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"controller"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"Pet"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),a("span",{attrs:{class:"token string"}},[t._v('"action"')]),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v('"find"')]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),a("p",[t._v("Controller function:")]),t._v(" "),a("div",{staticClass:"language-js extra-class"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[t._v("find"),a("span",{attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),a("span",{attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),a("span",{attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("model "),a("span",{attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{attrs:{class:"token string"}},[t._v("'Pet'")]),a("span",{attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),a("span",{attrs:{class:"token keyword"}},[t._v("try")]),t._v(" "),a("span",{attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{attrs:{class:"token keyword"}},[t._v("this")]),a("span",{attrs:{class:"token punctuation"}},[t._v(".")]),t._v("body "),a("spa
|