question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I would like to build a reusable CRUD view class on top of flask-rest-api. I built one previously fairly close to flask-restful’s design, and was wondering if anything currently exists or you have tips or suggestions of how to proceed.

The problem I am trying to solve is building the same list/get/update/delete endpoints over and over for various DB models. I want to declare things like access controls, default schema for serialization, what fields are permitted to update, DB model class, relationships to prefetch (i.e. joinedload) for list view, and auto-registration of endpoints via __init_subclass__.

Anything you’d suggest or like to see? Anything like this exist already on top of flask-rest-api?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
revmischacommented, Jul 3, 2019

I get what you mean about needing to override details. I’ve worked with these libraries before in both perl and python, and it’s mostly a matter of creating a base class and defining the parameters you mention in class vars, and then having default implementations of the methods list, get, create, update, delete.

0reactions
zedrdavecommented, Jun 12, 2021

@lafrech Dunno whether to reopen this or start a new thread.

I ran into something similar a while back and did end up creating my own CRUD blueprint class. Would be happy to try and refactor it into something usable in flask-smorest, if you think this might be of interest.

My approach is similar to @revmischa above (with a few differences)…

  • a CRUD class that inherits from flask-smorest’s Blueprint
  • take a number of class/var names as arguments to define Model, Argument/Response Schema, key etc. With some good default in place (camelcased endpoint name + “Schema” etc) which make it seamless for most cases.
  • relying on sqlalchemy for DB operations (I did once implement a variant that handled MongoDB, so both might be possible, but half the code would differ).
  • access control is handled separately (I use decorators on classes/endpoints with a permission/rule system) and added to the CRUD class as callbacks.

I think an access-control framework, and a CRUD class, would be two really useful additions to smorest, and decrease cruft/code-repetition hugely. Maybe worth workshopping the needs/implementation details before working on a Pull Request…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a Reusable CRUD RESTful Web Service ... - InformIT
Expert programmer Jesse Smith shows you how you can save time by creating a reusable CRUD RESTful web service.
Read more >
Node:CRUD examples to demonstrate using a reusable ...
Node:CRUD examples to demonstrate using a reusable helper function to execute promises in sequence. While working on a Node application, ...
Read more >
Crud Bud Reusable Glass Cleaner - 16.9oz - Walmart.com
Breaking down residue, gunk and crud with ease to make your glassware look new again. Each bottle contains 16.9oz of reusable cleaner liquid,...
Read more >
Reusable Crud Service Llai - StackBlitz
import { Component } from '@angular/core';. import { UserService } ...
Read more >
Generate CRUD procedures for a table - Documentation
SQL Complete generates customizable and reusable CRUD procedures for any particular table that can be executed in the following way:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found