Forráskód Böngészése

docs: Add note on making a request

Relates to #48
Michael Bromley 7 éve
szülő
commit
48a2dc2321
1 módosított fájl, 33 hozzáadás és 0 törlés
  1. 33 0
      README.md

+ 33 - 0
README.md

@@ -48,6 +48,39 @@ Vendure uses [TypeORM](http://typeorm.io), so it compatible will any database wh
 * `yarn start`
 * Go to http://localhost:4200 and log in with "superadmin", "superadmin"
 
+### Making a request
+
+When making an API request, it must include a `vendure-token` header with the value 
+being the channel token of the active channel. This value is set in the config by the
+`defaultChannelToken` property. If this is not set, or does not match a valid channel token,
+you will get the error `No valid channel was specified`
+
+For example:
+```TypeScript
+// bootstrap code
+bootstrap({
+    port: 3000,
+    apiPath: 'api',
+    defaultChannelToken: 'default-channel'
+    // ...
+})
+```
+
+```TypeScript
+// API call
+fetch(
+    'http://localhost:3000/api',
+    {
+        headers: {
+            'content-type': 'application/json',
+            'vendure-token': 'default-channel',
+        },
+        body: '{"query":"mutation { login(username: \\"superadmin\\", password: \\"superadmin\\") { user { id } } }"}',
+        method: 'POST',
+    },
+)
+```
+
 ### Code Generation
 
 [graphql-code-generator](https://github.com/dotansimha/graphql-code-generator) is used to automatically create TypeScript interfaces