How do I assign an attachment to a post using only the REST API?

If you look at the documentation for the media endpoint, you’ll see there’s a field, post, that you can use to attach media to a post using its ID.

post The ID for the associated post of the attachment.