This integration guide is following the Quick Start Guide. We assume that you have fully completed its "Hands-on" path, and therefore can consume the API by browsing this url(opens new window).
If you haven't gone through the Quick Start Guide, the way you request a Strapi API with Nuxt 3(opens new window) remains the same except that you will not fetch the same content.
# GET Request - get list of entities or one entity
Execute a GET request on the restaurant collection type in order to fetch your restaurants.
Be sure that you activated the find and findOne permission for the restaurant collection type.
@nuxtjs/strapi exposes composables that are auto-imported by Nuxt 3. Note that delete function must be renamed because it's reserved word in JavaScript.
// Get all restaurantsconst response =await find<Restaurant>('restaurants')// Get one restaurant by idconst response =await findOne<Restaurant>("restaurants", restaurantId)
1 2 3 4 5
Example GET request with $fetch
// Get all restaurantsconst response =$fetch("http://localhost:1337/api/restaurants")// Get one restaurant by idconst response =await$fetch(`http://localhost:1337/api/restaurants/${restaurantId}`)
1 2 3 4 5
Example response
// List of the restaurants{"data":[{"id":1,"attributes":{"name":"Biscotte Restaurant","description":"Welcome to Biscotte restaurant! \nRestaurant Biscotte offers a cuisine based on fresh, quality products, often local, organic when possible, and always produced by passionate producers.","createdAt":"2022-10-29T09:37:55.061Z","updatedAt":"2022-11-07T18:53:27.702Z","publishedAt":"2022-10-29T09:47:48.782Z"}},{"id":2,"attributes":{"name":"Dolemon Sushi","description":"Unmissable Japanese Sushi restaurant. The cheese and salmon makis are delicious.","createdAt":"2022-10-29T09:37:55.061Z","updatedAt":"2022-11-07T18:53:27.702Z","publishedAt":"2022-10-29T09:47:48.782Z"}}],"meta":{"pagination":{"page":1,"pageSize":25,"pageCount":1,"total":4}}}// One restaurant{"data":{"id":1,"attributes":{"name":"Biscotte Restaurant","description":"Welcome to Biscotte restaurant! \nRestaurant Biscotte offers a cuisine based on fresh, quality products, often local, organic when possible, and always produced by passionate producers.","createdAt":"2022-10-29T09:37:55.061Z","updatedAt":"2022-11-07T18:53:27.702Z","publishedAt":"2022-10-29T09:47:48.782Z"}},"meta":{}}
Source code used in this article can be found in this(opens new window) repo. It's tiny CRUD app that demostrates basic features of interacing between Nuxt frontend and Strapi backend.
Here is how to request your collection types in Strapi using Nuxt.js. When you create a collection type or a single type you will have a certain number of REST API endpoints available to interact with.
We used the GET, POST, PUT and DELETE methods here. Learn more about API Endpoints.