Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit client API docs #2145

Merged
merged 21 commits into from
Dec 1, 2021
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
HTTP API using auth token
  • Loading branch information
EugeniyBurmistrov committed Nov 15, 2021
commit 464a3423ef72e0ed61f1676ee674e3f27be14ad1
55 changes: 40 additions & 15 deletions docs/api/client/http-api.md
Original file line number Diff line number Diff line change
@@ -88,22 +88,47 @@ The request body should have the `application/json` content type and contain the
| **commandType** | string | The command type that the aggregate can handle |
| **payload** | object | Parameters the command accepts |

##### Example
## Authorization

Use the following command to add an item to the **shopping-list** example:
To authorize your request on a reSolve server, specify a Bearer Token in your request's Authorization header:

```sh
$ curl -X POST "http://localhost:3000/api/commands"
--header "Content-Type: application/json" \
--data '
{
"aggregateName":"Todo",
"type":"createItem",
"aggregateId":"root-id",
"payload": {
"id":`date +%s`,
"text":"Learn reSolve API"
}
```js
await fetch(Url, {
...
headers: {
Authorization: `Bearer ${jwt}`,
...
},
...
})
```

See the [Authentication and Authorization](../../authentication-and-authorization.md) topic for information on how authorization is handled on server.
EugeniyBurmistrov marked this conversation as resolved.
Show resolved Hide resolved

## Example

The code sample bellow demonstrates how to implement a JavaScript function that sends the specified command to a reSolve server with authorization.

```js
const sendCommand = async ({
aggregateName,
aggregateId,
type,
payload,
jwt,
}) => {
await fetch(apiCommandsUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${jwt}`,
},
body: JSON.stringify({
aggregateName,
aggregateId,
type,
payload,
}),
})
}
'
```