Skip to content

Commit c190848

Browse files
committed
Improved introduction
1 parent 3a354dc commit c190848

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

docs/getting-started/dotnet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
title: .NET
2+
3+
Add the `TypedRest` NuGet package to your project.
4+
5+
Create a class derived from `EntryEndpoint`.

docs/getting-started/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
title: Overview
2+
3+
TypedRest is available for multiple platforms/languages. Please choose one of the following Getting Started Guides:
4+
5+
- [.NET](dotnet.md)
6+
- [Java](java.md)

docs/getting-started/java.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
title: Java
2+
3+
Add the `com.oneandone:typedrest-core` Maven dependency to your project.
4+
5+
Create a class derived from `EntryEndpoint`.

docs/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
TypedRest helps you build type-safe, fluent-style REST API clients.
22

33
Common REST patterns such as collections are represented as classes, allowing you to write more idiomatic code. For example, TypedRest lets you turn this:
4+
45
```csharp
56
var httpClient = new HttpClient {BaseAddress = new Uri("http://example.com/")};
67
var response = httpClient.GetAsync("/contacts/123");
78
var contact = await response.Content.ReadAsAsync<ContactDto>();
89
```
910

1011
into this:
12+
1113
```csharp
1214
var myService = new MyServiceClient(new Uri("http://example.com/"));
1315
var contact = myService.Contacts["123"].ReadAsync();
1416
```
1517

16-
Read more about the **[Motivation](motivation.md)** behind TypedRest,
17-
or get started now with **[.NET](https://github.com/TypedRest/TypedRest-DotNet)** or **[Java](https://github.com/TypedRest/TypedRest-Java)**!
18+
Read the **[Introduction](introduction.md)** to TypedRest or jump right in with the **[Getting started](getting-started/index.md)** guide.
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ Pretty standard stuff, right? The problem is that all this knowledge currently o
1010
var client = new HttpClient {BaseAddress = new Uri("http://example.com/")};
1111

1212
var contactsResponse = await client.GetAsync("contacts");
13-
var contactList = await contactsResponse.Content.ReadAsAsync<List<ContactDto>>();
13+
var contactList = await contactsResponse.Content.ReadAsAsync<List<Contact>>();
1414

1515
var janeResponse = await client.GetAsync("contacts/jane");
16-
var jane = await janeResponse.Content.ReadAsAsync<ContactDto>();
16+
var jane = await janeResponse.Content.ReadAsAsync<Contact>();
1717

18-
await client.PostAsJsonAsync("contacts", new ContactDto("John"));
18+
await client.PostAsJsonAsync("contacts", new Contact("John"));
1919
```
2020

2121
This is where TypedRest comes in. TypedRest is a .NET and Java library for consuming RESTful APIs that behave in a "predictable" way. Rather than applying your knowledge about how a REST collection usually behaves you simply tell the library that this particular endpoint *is* a collection and get a collection-like interface in return.
2222

2323
```csharp
2424
var myService = new EntryEndpoint(new Uri("http://example.com/"));
25-
var contacts = new CollectionEndpoint<ContactDto>(myService, relativeUri: "./contacts");
25+
var contacts = new CollectionEndpoint<Contact>(myService, relativeUri: "./contacts");
2626

2727
var contactList = await contacts.ReadAllAsync();
2828
var jane = await contacts["jane"].ReadAsync();
29-
await contacts.CreateAsync(new Contact("john"));
29+
await contacts.CreateAsync(new Contact("John"));
3030
```
3131

3232
TypedRest uses a classic object-oriented approach to provide you with building blocks for modeling [RESTful endpoints](endpoints/index.md). Behavior of endpoints is described by inheritance while navigation between them is described by composition. For example, we could redesign our sample from above to make the service's functionality easy to discover and consume using code completion:
@@ -37,7 +37,7 @@ class MyServiceClient : EntryEndpoint
3737
public MyServiceClient(Uri uri) : base(uri)
3838
{}
3939

40-
public ICollectionEndpoint<ContactDto> Contacts => new CollectionEndpoint<ContactDto>(this, relativeUri: "./contacts");
40+
public ICollectionEndpoint<Contact> Contacts => new CollectionEndpoint<Contact>(this, relativeUri: "./contacts");
4141
}
4242
```
4343

@@ -47,7 +47,7 @@ The consuming code could look this:
4747
var myService = new MyServiceClient(new Uri("http://example.com/"));
4848
var contactList = await myService.Contacts.ReadAllAsync();
4949
var jane = await myService.Contacts["jane"].ReadAsync();
50-
await myService.Contacts.CreateAsync(new ContactDto("john"));
50+
await myService.Contacts.CreateAsync(new Contact("john"));
5151
```
5252

5353
TypedRest is all about nomenclature and patterns. An endpoint describes any resource addressable via an URI.
@@ -82,23 +82,25 @@ class MyServiceClient : EntryEndpoint
8282
// The TElementEndpoint type argument allows you to customize the specific type of element endpoint it creates.
8383
class ContactCollectionEndpoint : CollectionEndpointBase<Contact, ContactEndpoint>
8484
{
85-
// Hard-coding the relative URI here makes the constructor signature nicer
85+
// Hard-coding the relative URI here makes the constructor signature simpler
8686
public ContactCollectionEndpoint(IEndpoint referrer) : base(referrer, relativeUri: "./contacts")
8787
{}
8888
}
8989

90-
class ContactEndpoint : ElementEndpoint<ContactDto>
90+
class ContactEndpoint : ElementEndpoint<Contact>
9191
{
9292
public ContactEndpoint(IEndpoint referrer, Uri relativeUri) : base(referrer, relativeUri)
9393
{}
9494

95-
public IElementEndpoint<NoteDto> Notes => new ElementEndpoint<NoteDto>(this, relativeUri: "./notes");
95+
public IElementEndpoint<Note> Notes => new ElementEndpoint<Note>(this, relativeUri: "./notes");
9696
}
9797
```
9898

9999
The consuming code could look this:
100100

101101
```csharp
102102
var myService = new MyServiceClient(new Uri("http://example.com/"));
103-
await myService.Contacts["jane"].Notes.SetAsync(new NoteDto("some note"));
103+
await myService.Contacts["jane"].Notes.SetAsync(new Note("some note"));
104104
```
105+
106+
Continue on to the **[Getting started](getting-started/index.md)** guide.

0 commit comments

Comments
 (0)