ecommerce static method
Creates a comprehensive e-commerce API definition.
Implementation
static ApiDefinition ecommerce() {
return SimpleApiBuilder(
title: 'E-commerce API',
baseUrl: 'https://jsonplaceholder.typicode.com',
description: 'E-commerce API using JSONPlaceholder endpoints for testing',
)
// Posts as "Products"
.get('/posts',
name: 'Get Products',
queryParams: ['userId', '_limit', '_start'],
tags: ['products', 'read'],
responseType: 'List<Product>')
.get('/posts/{id}',
name: 'Get Product Details',
tags: ['products', 'read'],
responseType: 'Product')
.post('/posts',
name: 'Create Product',
tags: ['products', 'write'],
responseType: 'Product')
.put('/posts/{id}',
name: 'Update Product',
tags: ['products', 'write'],
responseType: 'Product')
.delete('/posts/{id}',
name: 'Delete Product',
tags: ['products', 'write'],
responseType: 'Product')
// Albums as "Categories"
.get('/albums',
name: 'Get Categories',
queryParams: ['userId', '_limit'],
tags: ['categories', 'read'],
responseType: 'List<Category>')
.get('/albums/{id}',
name: 'Get Category Details',
tags: ['categories', 'read'],
responseType: 'Category')
.get('/albums/{id}/photos',
name: 'Get Category Items',
queryParams: ['_limit', '_start'],
tags: ['categories', 'photos', 'read'],
responseType: 'List<Photo>')
// Todos as "Orders/Carts"
.get('/todos',
name: 'Get All Orders',
queryParams: ['userId', 'completed', '_limit', '_start'],
tags: ['orders', 'read'],
responseType: 'List<Order>')
.get('/todos/{id}',
name: 'Get Order Details',
tags: ['orders', 'read'],
responseType: 'Order')
.post('/todos',
name: 'Create Order',
tags: ['orders', 'write'],
responseType: 'Order')
.put('/todos/{id}',
name: 'Update Order',
tags: ['orders', 'write'],
responseType: 'Order')
.delete('/todos/{id}',
name: 'Delete Order',
tags: ['orders', 'write'],
responseType: 'Order')
// Users
.get('/users',
name: 'Get All Users',
queryParams: ['_limit', '_start'],
tags: ['users', 'read'],
responseType: 'List<User>')
.get('/users/{id}',
name: 'Get User Details',
tags: ['users', 'read'],
responseType: 'User')
.get('/users/{id}/posts',
name: 'Get User Products',
queryParams: ['_limit', '_start'],
tags: ['users', 'products', 'read'],
responseType: 'List<Product>')
.get('/users/{id}/albums',
name: 'Get User Categories',
queryParams: ['_limit', '_start'],
tags: ['users', 'categories', 'read'],
responseType: 'List<Category>')
.get('/users/{id}/todos',
name: 'Get User Orders',
queryParams: ['_limit', '_start', 'completed'],
tags: ['users', 'orders', 'read'],
responseType: 'List<Order>')
// Comments as "Reviews"
.get('/comments',
name: 'Get Product Reviews',
queryParams: ['postId', '_limit'],
tags: ['reviews', 'read'],
responseType: 'List<Review>')
.get('/comments/{id}',
name: 'Get Review Details',
tags: ['reviews', 'read'],
responseType: 'Review')
.get('/posts/{id}/comments',
name: 'Get Reviews for Product',
queryParams: ['_limit', '_start'],
tags: ['products', 'reviews', 'read'],
responseType: 'List<Review>')
.build();
}