I have the following packages in my project:
1. flask (webframework)
2. webargs and marshmallow for request and response definition
3. apispec and apispec-webframework.flask for generation of openapi 3.0 doc.
Our project has chosen to use MethodView from flask to define APIs. One of our API looks like the following.
POST /resource/<resource-id>
{
"attribute-1": <attribute-value1>,
"attribute-2": <attribute-value1>,
}
The apispec documentation lists how to specify responses but there is no clear way of defining the input from path (resource-id) and request body (attributes).
https://apispec.readthedocs.io/en/stable/using_plugins.html?highlight=MethodView
I would appreciate if someone could clarify how to use webargs and marshmallow to define the input for a MethodView:post() method for the above API.
Related
I am using a flask tutorial that I found here...
https://andrewgriffithsonline.com/blog/180412-deploy-flask-api-any-serverless-cloud-platform/
In the "Test the App" section, there is a "http-prompt" command used. I do not want to use that. Instead I will like to use python requests module.
Sometimes response of a service is too large that swagger cannot get and beautify response as json.
if we try with "curl" command, we get response very fast. I think this is because of "Syntax highlighting" configuration of swagger.
In this url, we can understand that one way is change this config:
springdoc.swagger-ui.syntaxHighlight.activated=false
Do you have any idea in wso2 apim 4.1.0?
Can we change API Definition for this? or we have to change core configs of wso2?
With advanced UI customization you should be able to get this done. Please refer - https://apim.docs.wso2.com/en/latest/reference/customize-product/customizations/advanced-ui-customization/
You will have to customize the Swagger UI and add the springdoc.swagger-ui.syntaxHighlight.activated property there.
In[1], it is added springdoc.swagger-ui.validatorUrl for the Swagger UI.
[1] -
https://github.com/wso2/apim-apps/blob/main/portals/devportal/src/main/webapp/source/src/app/components/Apis/Details/ApiConsole/SwaggerUI.jsx#L32
I'm working on django rest framework viewset and want to know which HTTP methods map to the functions:
1.list()
2.create()
3.retrieve()
4.update()
5.partial_update()
6.destroy()
I have searched a lot but I didn't got the specific answer to my question.
So I just want to know which http method maps all the above listed functions
thanks in advance!!
You can see Django Rest Framework code and see in routers.py file methods mapping, e.g. in SimpleRouter:
GET: list() and retrieve()
POST: create()
PUT: update()
PATCH: partial_update()
DELETE: destroy()
In simple way you can say:
1.list(): HTTP Get
2.create(): HTTP Post
3.retrieve(): HTTP Get
4.update(): HTTP Put
5.partial_update(): HTTP Patch
6.destroy(): HTTP Delete
I found woefully few samples of httplib2 using the following template defined in the httplib2 documents.
The following (GETs) work (and I now need to implement POST methods using it)
URLS = (
'/', 'PingLocal',
'/ping', 'PingLocal',
'/ping/silo', 'PingSilo'
)
class PingLocal(object):
def GET(self):
return json.dumps({'time': time.strftime('%m/%d/%Y %I:%M:%S'), 'message': 'XYZ Server Responding to Ping'})
How to implement POST methods and pass data (body) to the post request?
A few examples I did come across do not use this suggested
"URLS-list / Classes" model.
Any pointers appreciated. Thank you.
I made a mistake.
In the code I am implementing the REST Server AND in the implemented methods - I am in turn making REST client calls to remote URIs.
I am using httplib2 to make those REST client calls (as the library documentation clearly mentions - its the client library).
I am in turn using web.py module to implement the REST server - and found the relevant documentation there.
Thank you
Using a decorator I was trying to add a method to WSGIRequest request, just like is_ajax().
Since I could not find a proper way I just updated request.META with the info needed.
Should I look into adding method at runtime in Python ?
You can try to write custom middleware and add this method to request during request process.
See this for more info how to write middleware:
http://docs.djangoproject.com/en/dev/topics/http/middleware/#writing-your-own-middleware
http://www.djangobook.com/en/beta/chapter16/