Skip to content

Commit 1d8561c

Browse files
switch to PUT
1 parent 7915f5c commit 1d8561c

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

learn/getting-started/create-your-first-application.mdx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ With everything in place, now its time to create your first record for the `Dog`
214214

215215
With the automatic REST API generation you have a plethora of options for interacting with the `Dog` table. We'll keep it simple for now, but will explore everything this has to offer in later guides.
216216

217-
Create a `POST` request using the REST API port and the `/Dog/` endpoint (don't forget the trailing slash). Include a JSON body with the specified attributes except for `id`:
217+
Create a `PUT` request using the REST API port and the path `/Dog/001`. Include a JSON body with the specified attributes except for `id`. The `001` in the URL will be used as the ID for this entry.
218218

219219
:::note
220220
If you're using Fabric remember to replace the `localhost` with your cluster's URL
@@ -224,22 +224,23 @@ If you're using Fabric remember to replace the `localhost` with your cluster's U
224224
<TabItem value="curl">
225225

226226
```bash
227-
curl 'http://localhost:9926/Dog/' \
228-
-X POST \
227+
curl 'http://localhost:9926/Dog/001' \
228+
-X PUT \
229229
-H "Content-Type: application/json" \
230230
-d '{
231231
"name": "Harper",
232232
"breed": "Black Labrador / Chow Mix",
233233
"age": 5
234-
}' | jq
234+
}' \
235+
-w "%{http_code}"
235236
```
236237

237238
</TabItem>
238239
<TabItem value="fetch">
239240

240241
```typescript
241-
const response = await fetch('http://localhost:9926/Dog/', {
242-
method: 'POST',
242+
const response = await fetch('http://localhost:9926/Dog/001', {
243+
method: 'PUT',
243244
headers: {
244245
'Content-Type': 'application/json',
245246
},
@@ -249,33 +250,30 @@ const response = await fetch('http://localhost:9926/Dog/', {
249250
age: 5,
250251
}),
251252
});
252-
const id = await response.text();
253-
console.log(id);
253+
console.log(response.status);
254254
```
255255

256256
</TabItem>
257257
</Tabs>
258258

259-
If you see a 36-character ID returned, then the record was successfully created!
260-
261-
With Harper tables, the `POST` method automatically generates IDs for you. You can still specify IDs yourself using a `PUT` method, and we'll explore those details in a future guide.
259+
If you see `204` status code, then the record was successfully created!
262260

263261
## Read a Record
264262

265-
Now, with the returned ID, create a `GET` request to the endpoint `/Dog/<id>`:
263+
Now, with the returned ID, create a `GET` request to the endpoint `/Dog/001`:
266264

267265
<Tabs groupId="http-client">
268266
<TabItem value="curl">
269267

270268
```bash
271-
curl -s 'http://localhost:9926/Dog/<id>' | jq
269+
curl -s 'http://localhost:9926/Dog/001' | jq
272270
```
273271

274272
</TabItem>
275273
<TabItem value="fetch">
276274

277275
```typescript
278-
const response = await fetch('http://localhost:9926/Dog/<id>');
276+
const response = await fetch('http://localhost:9926/Dog/001');
279277
const dog = await response.json();
280278
console.log(dog);
281279
```
@@ -290,15 +288,15 @@ You should see the record we just created returned as JSON:
290288
"name": "Harper",
291289
"breed": "Black Labrador / Chow Mix",
292290
"age": 5,
293-
"id": "<id>"
291+
"id": "001"
294292
}
295293
```
296294

297295
## Query a Record
298296

299297
The REST API isn't just for basic CRUD operations. It can also be used to create search queries using URL query strings.
300298

301-
Start by creating another `GET` query, but this time do not include the `<id>` part. Make sure to include a trailing slash. Then, include a query string containing an attribute and a value such as `?age=5`.
299+
Start by creating another `GET` query, but this time do not include the ID (`001`) part. Make sure to include a trailing slash. Then, include a query string containing an attribute and a value such as `?age=5`.
302300

303301
<Tabs groupId="http-client">
304302
<TabItem value="curl">
@@ -327,7 +325,7 @@ Search queries return a list of records that match the specified conditions, in
327325
"name": "Harper",
328326
"breed": "Black Labrador / Chow Mix",
329327
"age": 5,
330-
"id": "<id>"
328+
"id": "001"
331329
}
332330
]
333331
```
@@ -348,7 +346,7 @@ Push-based deployments is powered by the Harper CLI and is where your the user w
348346

349347
For a true production application, Harper recommends using pull-based deployments so that you can deploy tagged versions of your application repository. But for development and experimentation, push-based is perfectly fine. Later guides will explore pull-based deployment workflows in more detail.
350348

351-
To get started with push-based deployments, open a command line and set the current directory to the application directory. Run the `harper deploy` command using the Fabric clusters URL, username, and password:
349+
To get started with push-based deployments, open a command line and set the current directory to the application directory. Run the `harper deploy` command using the Fabric cluster's URL, username, and password:
352350

353351
```bash
354352
harper deploy \

0 commit comments

Comments
 (0)