simple_webdav_client 0.2.0 copy "simple_webdav_client: ^0.2.0" to clipboard
simple_webdav_client: ^0.2.0 copied to clipboard

A Dart WebDAV client with full RFC 4918 support, including file operations, property management, and locking (LOCK/UNLOCK). Ideal for these needing complete WebDAV functionality.

Simple WebDAV Client #

Package Likes Popularity Points

simple_webdav_client is a Dart WebDAV client with full RFC 4918 support, including file operations (PUT/GET/CREATE/DELETE/MKCOL/MOVE/COPY), property management (PROPFIND/PROPUPDATE), and locking (LOCK/UNLOCK). Ideal for these needing complete WebDAV functionality.

Client's API invocation style is similar to HttpClient and works more easily with async programming. refer to here for more exmaples.

Features #

Following methods have been implemented:

Propfind #

Used to retrieve properties defined on the resource identified by the Request-URI. see RFC4918#9.1 for more information.

You can make a direct request or use the dispatcher's API to make a request (following related sections will not be repeated).

// openUrl
client.openUrl(
    method: WebDavMethod.propfind,
    url: url,
    // Use [PropfindPropRequestParam] to specify the properties to be requested,
    // [PropfindAllRequestParam] to retrieve as many live properties as possible,
    // and [PropfindNameRequestParam] to retrieve all property names.
    param: PropfindPropRequestParam(...),
);
// api
client.dispatch(url).findProps(...);
client.dispatch(url).findAllProps(...);
client.dispatch(url).findPropNames(...);

Proppatch #

Used to set and/or remove properties defined on the resource identified by the request-URI. see RFC4918#9.2 for more information.

// openUrl
client.openUrl(
    method: WebDavMethod.propfind,
    url: url,
    param: ProppatchRequestParam(...),
);
// api
client.dispatch(url).updateProps(...);

Mkcol/Put #

Creates new (collection) resource at the location specified by the Request-URI. see RFC4918#9.3 - MKCOL and RFC4918#9.7 - PUT for more information.

// openUrl
client.openUrl(
    method: WebDavMethod.propfind,
    url: url,
    // mkcol: MkcolRequestParam
    // put: PutRequestParam
    param: MkcolRequestParam(...),
);
// api
client.dispatch(url).create(...);
client.dispatch(url).createDir(...);

Get/Head/Post #

Same as the HTTP methods defined in RFC7231.

// openUrl
client.openUrl(
    method: WebDavMethod.propfind,
    url: url,
    // get: GetRequestParam
    // head: HeadRequestParam
    // post: PostRequestParam
    param: GetRequestParam(...),
);
// api: get
client.dispatch(url).get(...);

Delete #

Deletes resource identified by the Request-URI. see RFC4918#9.6 for more information.

// openUrl
client.openUrl(
    method: WebDavMethod.propfind,
    url: url,
    param: DeleteRequestParam(...),
);
// api
client.dispatch(url).delete(...);
client.dispatch(url).deleteDir(...);

Copy #

Create a copy of the source resource. see RFC4918#9.8 for more information.

// openUrl
client.openUrl(
    method: WebDavMethod.propfind,
    url: url,
    param: CopyRequestParam(...),
);
// api
client.dispatch(url).copy(...);
client.dispatch(url).copyDir(...);

Move #

Move a resource to a new location. see RFC4918#9.9 for more information.

// openUrl
client.openUrl(
    method: WebDavMethod.propfind,
    url: url,
    param: MoveRequestParam(...),
);
// api
client.dispatch(url).move(...);
client.dispatch(url).moveDir(...);

Lock #

Used to Request lock on a resource. see RFC4918#9.10 for more information.

// openUrl
client.openUrl(
    method: WebDavMethod.propfind,
    url: url,
    param: LockRequestParam(...),
);
// api
client.dispatch(url).createLock(...);
client.dispatch(url).createDirLock(...);
client.dispatch(url).renewLock(...);

Unlock #

Removes the lock identified by the token in Lock-Token. see RFC4918#9.11 for more information.

// openUrl
client.openUrl(
    method: WebDavMethod.propfind,
    url: url,
    param: UnlockRequestParam(...),
);
// api
client.dispatch(url).unlock(...);

Usage #

Check test cases in dir:intergration_test/methods_test and example/main.dart for more examples.

1. Example - full request #

WebDavClient.std().dispatch(newFilePath)
    .findAllProps(includes: [PropfindRequestProp('author', 'CUSTOM:')])
    .then((request) => request.close())
    .then((response) => response.parse())
    .then((result) => print(result?.toDebugString()));

2. Example - request with custom parser #

BaseRespResultParser generateParser() {
  final propParsers = Map.of(kStdPropParserManager);
  propParsers[(name: "author", ns: "CUSTOM:")] = const StringPropParser();

  final propstatParser = BasePropstatElementParser(
      parserManger: WebDavResposneDataParserManger(parsers: propParsers),
      statusParser: const BaseHttpStatusElementParser(),
      errorParser: const BaseErrorElementParser());
  final responseParser = BaseResponseElementParser(
      hrefParser: const BaseHrefElementParser(),
      statusParser: const BaseHttpStatusElementParser(),
      propstatParser: propstatParser,
      errorParser: const BaseErrorElementParser(),
      locationParser: const BaseHrefElementParser());
  final multistatParser =
      BaseMultistatusElementParser(responseParser: responseParser);

  final parsers = Map.of(kStdElementParserManager);
  parsers[(name: WebDavElementNames.multistatus, ns: kDavNamespaceUrlStr)] =
      multistatParser;

  return BaseRespResultParser(
      singleResDecoder: kStdResponseResultParser.singleResDecoder,
      multiResDecoder: BaseRespMultiResultParser(
          parserManger: WebDavResposneDataParserManger(parsers: parsers)));
}

final parser = generateParser();

// openUrl
client.openUrl(
    method: WebDavMethod.propfind,
    url: url,
    param: ...,
    responseResultParser: parser
);
// dispatch
WebDavClient.std().dispatch(newFilePath, responseResultParser: parser);

"Buy Me A Coffee" Alipay WechatPay

ETH BTC

License #

MIT License

Copyright (c) 2024 Fries_I23

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1
likes
160
pub points
45%
popularity

Publisher

unverified uploader

A Dart WebDAV client with full RFC 4918 support, including file operations, property management, and locking (LOCK/UNLOCK). Ideal for these needing complete WebDAV functionality.

Repository (GitHub)
View/report issues

Topics

#webdav #webdav-client #rfc4918

Documentation

API reference

Funding

Consider supporting this project:

www.buymeacoffee.com

License

MIT (license)

Dependencies

universal_io, xml

More

Packages that depend on simple_webdav_client