Giter Club home page Giter Club logo

Comments (3)

honzajavorek avatar honzajavorek commented on September 24, 2024

Documentation says @marshal_with(resource_fields) is equivalent to return marshal(db_get_todo(), resource_fields), 200 directly in method serving the response.

I think solution to your problem would be simply to give different resource_fields to your get method than to your post method, or directly adjusting the dict according to current request.

from flask-restful.

sibblegp avatar sibblegp commented on September 24, 2024

Marshal with is regarding the objects returned, not the objects send to an endpoint.

For instance, at my users.json endpoint, for GET, I have:

api_key (Required)
use_cache
user_id (Required)

For my POST, I need:

api_key (Required)
user_name (Required)
first_name (Required)
etc.

So the fields sent to the endpoint differ entirely based upon the type of call. Just want an easy way to define that.

from flask-restful.

sibblegp avatar sibblegp commented on September 24, 2024

I guess I should be grateful when I can answer my own questions......just made a new parser for each endpoint type and included it in the later parsing:

    #Initialize the global parser
    self.parser = reqparse.RequestParser(API_Parameter)

    #Initialize other parsers
    self.parsers = {}
    self.parsers['GET'] = reqparse.RequestParser(API_Parameter)
    self.parsers['POST'] = reqparse.RequestParser(API_Parameter)
    self.parsers['PUT'] = reqparse.RequestParser(API_Parameter)
    self.parsers['DELETE'] = reqparse.RequestParser(API_Parameter)

Then:

    self.query_args = self.parser.parse_args()
    self.query_args.update(self.parsers['GET'].parse_args())

from flask-restful.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.