Skip to content

Add Content and Stream API documentation - #108

Draft
cgl wants to merge 1 commit into
mainfrom
docs/content-stream-api
Draft

cgl wants to merge 1 commit into
mainfrom
docs/content-stream-api

Conversation

@cgl

@cgl cgl commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

#30

@cgl
cgl requested a review from lovelydinosaur October 21, 2026 14:17
Comment thread docs/API.md Outdated
```python
>>> j = hip.JSON(...)
client = hip.Client()
form_content = hip.Form({'email': 'ada@example.com', 'message': 'Hello'})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use a single word variable here? content or data perhaps?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, maybe :)

Comment thread docs/API.md Outdated

```python
>>> f = hip.Form(...)
json_content = hip.JSON({'title': 'A short guide', 'published': True})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐼

Comment thread docs/API.md Outdated
Comment on lines +294 to +298
upload_content = hip.MultiPart(
form={'description': 'A butterfly'},
files={'image': hip.File('image.png')},
)
response = client.post('https://www.example.com/images', content=upload_content)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
upload_content = hip.MultiPart(
form={'description': 'A butterfly'},
files={'image': hip.File('image.png')},
)
response = client.post('https://www.example.com/images', content=upload_content)
upload = hip.MultiPart(
form={'description': 'A butterfly'},
files={'image': hip.File('image.png')},
)
response = client.post('https://www.example.com/images', content=upload)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this example reminds me that I like this API!

Comment thread docs/API.md Outdated
Comment on lines +355 to +357
Although `ByteStream`, `FileStream`, and `MultiPartStream` implement the `Stream`
interface, they are not part of hip’s public API. Use the `Stream` interface when
working with streams.

@lovelydinosaur lovelydinosaur Oct 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we find a way to word this that doesn't name the classes? Eg...

The Stream interface is public API, although the implementation classes themselves are private.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 47b1ebb

Comment thread docs/API.md Outdated
arriving. A short read does not by itself mean the stream has ended. When the
stream ends, a positive-size read returns b''.

`read(0)` returns `b''` without consuming data. Do not use it as an end-of-stream check.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the behaviour we want, because it's too easy to get caught out.

We could...

  • Use size <= 0 as the "Until EOF" indicator?
  • Raise ValueError on size=0?
  • Something more carefully explicit?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this for now!

Comment thread docs/API.md Outdated
Comment on lines +389 to +393
Content streams returned by `Content.open()` are read-only. Calling `write()` on
one raises `NotImplementedError`.

A `NetworkStream` supports `write(data)`. It sends the supplied bytes and returns
`None` on success.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not currently documenting / exposing NetworkStream, and it's not part of the core API. (ie. users don't need to know about it in order to write client/server level code)

Perhaps we can re-write this slightly to omit mentioning it.

Eg.

Most stream implementations are for read-only data sources. However the Stream interface also allows for read/write or write-only implementations.

Or something along those lines?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already a bit of a stretch, I think we can remove this line too.

@lovelydinosaur

Copy link
Copy Markdown
Member

Oh, thought...

Since we've actually only got stubbed out API docs at the moment, should we match that super-concise style, and then think more holistically about expanding this page... https://www.encode.io/hip/api/ ...into prose docs?

@cgl
cgl force-pushed the docs/content-stream-api branch from 0cd0db1 to 47b1ebb Compare October 23, 2026 09:58

@cgl cgl left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we've actually only got stubbed out API docs at the moment, should we match that super-concise style, and then think more holistically about expanding this page... https://www.encode.io/hip/api/ ...into prose docs?

I am keen to have a more progressive approach, such as matching the rest of the docs to this prose style. I can hold this PR unmerged until then.

Comment thread docs/API.md Outdated
arriving. A short read does not by itself mean the stream has ended. When the
stream ends, a positive-size read returns b''.

`read(0)` returns `b''` without consuming data. Do not use it as an end-of-stream check.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this for now!

Comment thread docs/API.md Outdated
Comment on lines +389 to +393
Content streams returned by `Content.open()` are read-only. Calling `write()` on
one raises `NotImplementedError`.

A `NetworkStream` supports `write(data)`. It sends the supplied bytes and returns
`None` on success.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already a bit of a stretch, I think we can remove this line too.

Comment thread docs/API.md Outdated
```python
>>> j = hip.JSON(...)
client = hip.Client()
form_content = hip.Form({'email': 'ada@example.com', 'message': 'Hello'})

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, maybe :)

Comment thread docs/API.md Outdated

```python
>>> f = hip.Form(...)
json_content = hip.JSON({'title': 'A short guide', 'published': True})

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐼

Comment thread docs/API.md Outdated
Comment on lines +355 to +357
Although `ByteStream`, `FileStream`, and `MultiPartStream` implement the `Stream`
interface, they are not part of hip’s public API. Use the `Stream` interface when
working with streams.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 47b1ebb

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants