Although this library is intended to be usable client side you will likely run into CORS issues so be careful about that.
The library is setup as an es6 class, and is initalized by passinging an object of options. The minimum requirements are
;const micropub =clientId: ''redirectUri: ''me: ''state: 'This should be secret or randomly generated per user';
If you already have other information stored such as the token and micropub endpoint you want to use you can also pass those in. The available options are:
me- The url of the user you are authenticating with
clientId- The url of your micropub client
redirectUri- The redirect url of your micropub client from indieauth. This is the page where you will get the code to exchange for an access token.
state- A custom identifier to validate a response from the auth endpoint
scope- The scope of the micropub client. Defaults to "post create delete update"
token- The authorization token
authEndpoint- The authorization endpoint
tokenEndpoint- The token endpoint to receive the access toke from
micropubEndpoint- The micropub enpoint
The first step is likely to be getting the authorization url to direct the user to.
The next step would be to exchange your code for an access token. You first need to initialize the library with the details you used to get the auth code and then pass the code to the auth token method:
Once you have your token, you can send queries to the micropub endpoint. The most likely queries are the
syndicate-to query. The result is retreived as an object.
If the micropub endpoint supports it you can query individual posts. Since it is slighty different to a basic query there is a different method to query about a post.
You can query all data on a post:
Or you can specify certain properties you wish to query:
You can run a create request with the microformats object for a post.
To send a request to delete or undelete a post just send run the appropriate method with the post url:
Update requests require the url of the post and the update data:
As of version
1.2.0 error handling is greatly improved.
If there are any errors you catch will come in an object:
message: 'Human readable string'status: null or the http status codeerror: null or further error information
Generally if there is a
status code that means the micropub endpoint returned an http error.
And if there is
error then there was an error sending the request at your end.
This might not be 100% accurate as there are a lot of potential errors.