I'm exploring using GraphQL-Django instead of building a large number of REST API endpoints. To that end I've successfully installed and am running the 'cookbook' sample app, part of the Graphene Django package: https://github.com/graphql-python/graphene-django
To better understand how the GraphQL technology works, I'm trying to make calls to the Graphene server with Postman. However I'm getting a CSRF error and have tried several things to resolve it, such as this:
Django returns 403 error on POST request with Fetch
But so far I've had no luck. Is there a definitive guide to using Postman with Graphene?
Robert
You probably want to be using graphiql rather than postman. But if you're having CSRF troubles (and want the url to be CSRF exempt... think hard on that) you can wrap the view in a csrf exemption. In your urls.py
from django.views.decorators.csrf import csrf_exempt
url(r'^graphql', csrf_exempt(GraphQLView.as_view(graphiql=True, schema=schema))),
You can use insomnia instead of postman. It's great with graphql.
But as #styryx answered, you should use csrf_exempt:
from django.urls import path
from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import GraphQLView
urlpatterns = [
path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=True))),
]
On this tutorial of a package of mine, is an example using insomnia client
Related
I am currently learning RESTFUL web service tutorial using postman software. However, I am not able to see the error message detail that was shown in my tutorial. May I know how can I get the "message" to be display in postman response body? Thank you.
Below show the example from my tutorial.
Whatever backend framework you are using look for the Environment Debug variable and set it to true if you are using laravel go to env file and set APP_DEBUG=true
I'm trying to get my feet wet with Nuxt.
I understand that there are different scenarios for data-fetching:
- First call: Server fetches data from api, prerenders html/app, sends whole page
- After that: App on client makes requests to api directly, only fetches json
This is handeld by nuxt automatically.
So I guess I have to expose my API to the client as well, correct?
Would I set the base-path of Axios in Nuxt to something like "http://www.myproj.com/api" ?
If yes, is there any way that nuxt can access the api locally when providing server-rendered content (for example "http://localhost:3333") instead?
Yes there is. When configuring axios in your nuxt.config.js you can set a baseURL and a browserBaseURL. Nuxt will use the baseURL when pre-rendering and the browserBaseURL from the client.
You can see this in the docs here.
If you are deploying to a vps you can have your api running on something like http://localhost:3333 and set that as your baseURL. For the browserBaseURL, if you are using https, you would want so set up an upstream for your api in nginx so that your browserBaseURL would be something like '/api'.
I'm using WP All Import to import an XML file. Their website states password protected files may be accessed via Basic HTTP Authentication, appending user credentials to the requested URL as such http://username:password#link-to-file. When attempted, the following error is returned:
RETS ReplyCode="20036" ReplyText="Missing User-Agent request header field."
The error is expected as the URL does not include headers required for authentication. From what I've researched, this method of passing credentials via the URL has been deprecated as it is unsecure. Do I need to create a function to pass the credentials to the server? I take it it's not quite as simple as "Basic HTTP Authentication."
I've contacted WP Import and thought I'd tap Stack while waiting. Any advice would be appreciated. Thank you
I've started working with MailChimp's api.
I've tried connecting to their servers using a rest call
based on a sample code I've found somewhere:
http://api.mailchimp.com/1.3/?output=json&method=campaignTemplateContent&apikey=MyKey-us2&cid=myId
Unfortounatly I keep getting this error:
{"error":"Invalid Mailchimp API Key: **MyKey**-us2 . You are accessing the wrong datacenter - your client library may not properly support our datacenter mapping scheme.","code":104}
I can't find any other code samples working on MailChimp's rest api.
What am I doing wrong here? Where are the code samples?
Thanks
Your URL is incorrect. You should be hitting http://us2.api.mailchimp.com instead of the one you're using.
I am new to Sinatra and want to get it working with oauth2-provider gem. I followed instruction https://github.com/songkick/oauth2-provider#readme and looked at example. But after i've got access_token, i can't get information from Oauth endpoint using this. It generate 401 not Unauthorized error. From my application i do request
http://localhost:9292/me?access_token=, i've tried html request as well as json request, but without success.
Anybody faced with this problem ?
Looks like you did your request using HTTP vs HTTPS. Did you try setting Songkick::OAuth2::Provider.enforce_ssl = false for now?