Serializer
Serializers are employed to transform the controller's response before sending it as an HTTP response.
Create a serializer
Usage
class BlogController {
getAllBlogs(DoxRequest req) async {
List<Blog> blogs = await Blog().all();
/// you can pass as list of data
return BlogSerializer(blogs);
}
findBlog(DoxRequest req, id) async {
Blog blog = await Blog().find(id);
/// or you can also pass as single data
return BlogSerializer(blog);
}
}
Info
You can pass as list of data or single data into the serializer. Just make sure that you have injected your model type in serializer Serializer<Blog>.