पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

पैकेज विवरणv0.1.0

annotated_shelf

एनोटेशन का उपयोग करके REST APIs बनाने के लिए शक्तिशाली Dart पुस्तकालय। सरल और स्पष्ट इंटरफ़ेस के साथ, आप तेज़, कुशल और उपयोग में आसान APIs का निर्माण आसानी से कर सकते हैं।

macOSWindowsLinux
30-दिन डाउनलोड
126
लाइक
23
Pub अंक
140

पैकेज इंस्टॉल करें

flutter pub add annotated_shelf

पैकेज अवलोकन

सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।

Annotated_Shelf एक शक्तिशाली Dart लाइब्रेरी है जो अनुमानों का उपयोग करके REST APIs के निर्माण को सरल बनाती है। यह मार्ग, अनुरोध हैंडलर और प्रतिक्रियाओं को कोड अनुमानों के माध्यम से परिभाषित करने के लिए एक साफ, स्पष्ट इंटरफेस प्रदान करती है। Shelf फ्रेमवर्क पर आधारित, यह विकासकर्ताओं को न्यूनतम बॉयलरप्लेट के साथ कुशल, प्रकार-सुरक्षित APIs बनाने की अनुमति देती है। त्वरित API विकास के लिए उपयुक्त, यह OpenAPI/Swagger डॉक्यूमेंटेशन के साथ बिना किसी दिक्कत के एकीकरण समर्थित है। लाइब्रेरी macOS, Windows और Linux पर चलती है, जिससे यह आर्किटेक्चर-स्वतंत्र बैकएंड सेवाओं के लिए उपयुक्त है।

उपयोग

  • न्यूनतम सेटअप के साथ RESTful APIs बनाना
  • कोड से OpenAPI दस्तावेज़ उत्पन्न करना
  • बैकएंड सेवाओं का त्वरित प्रोटोटाइपिंग
  • अनुमानों का उपयोग करके प्रकार सुरक्षित एंडपॉइंट बनाना
  • मौजूदा Dart प्रोजेक्ट्स के साथ एकीकरण

मुख्य विशेषताएँ

  • एनोटेशन-आधारित रूट परिभाषा
  • उच्च प्रदर्शन के लिए शेल्फ पर निर्मित
  • स्वचालित OpenAPI/Swagger संदर्भ
  • अनुरोध/प्रतिक्रिया मॉडलिंग समर्थित
  • प्लेटफॉर्म के अनुकूलता

इनके लिए उपयुक्त

  • Dart विकासक बैकएंड API बना रहे हैं
  • त्वरित API स्केलों की आवश्यकता वाली टीमें
  • OpenAPI एकीकरण की आवश्यकता वाले प्रोजेक्ट
  • घोषणात्मक कोडिंग शैली पसंद करने वाले विकासकर्ता
  • कई प्लेटफॉर्म के लिए बैकएंड सेवाएँ

विचार योग्य बातें

  • Dart अनुलेखों के साथ परिचित होना आवश्यक है
  • शेल्फ-आधारित सर्वर आर्किटेक्चर पर सीमित
  • जटिल रूटिंग के लिए अतिरिक्त कॉन्फ़िगरेशन की आवश्यकता हो सकती है
  • छोटे से मध्यम आकार के API के लिए सबसे उपयुक्त
  • दस्तावेज़ उत्पादन अंकन की सटीकता पर निर्भर करता है

मूल README

संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।

Annotated Shelf

Powerful, Lightweight, Fast development, Easy to learn

Documentation:

https://annotated-shelf.readthedocs.io/en/features-add_docs/index.html

Annotated Shelf is a powerful and lightweight Dart framework for generating REST APIs using annotations. Based on the popular Shelf library. Annotated Shelf provides a simple and intuitive interface for building APIs fast, efficiently, and easy to use without losing what Shelf can offer.

Features

  • Support for multiple HTTP methods and request types.
  • Support for File upload.
  • Automatic validation of request parameters.
  • Automatic Error responses based on exceptions.

Installation

To install Annotated Shelf, add it as a dependency in your pubspec.yaml file:

dependencies:
  annotated_shelf: ^0.1.0

Then, run pub get to install the package.

Getting Started

To use Annotated Shelf to create a REST API, import the library and annotate your models and controllers with the following annotations:

@RestAPI,
@GET,
@POST,
@PUT,
@DELETE,
@PATCH,

Annotated Shelf will automatically generate the necessary routes and endpoints based on the annotations you have provided.

Example

import 'package:annotated_shelf/annotated_shelf.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;

const _hostname = 'localhost';
const _port = 8080;
var itemsList = [Item("first item"), Item("second Item")];

class Item extends Payload {
  final String? name;

  Item(this.name);

  @override
  factory Item.fromJson(Map<String, dynamic> json) {
    return Item(json["name"]);
  }
  @override
  Map<String, dynamic> toJson() => {"name": name};
}

class TestForm extends Form {
  String name;
  int number;
  File image;

  TestForm(this.name, this.number, this.image);

  @override
  factory TestForm.fromJson(Map<String, dynamic> json) {
    return TestForm(
      json['name'] as String,
      json['number'] as int,
      File.fromJson(json['image'] as Map<String, dynamic>),
    );
  }

  @override
  Map<String, dynamic> toJson() => <String, dynamic>{
        'name': name,
        'number': number,
        'image': image,
      };
}

@RestAPI(baseUrl: '/to-do/list')
class ItemsAdaptor {
  @GET()
  List<Item> getAllItems(Request request) {
    return itemsList;
  }

  @GET(url: "/<itemName>")
  Item getItemByName(String itemName) {
    var index = itemsList.lastIndexWhere((element) => element.name == itemName);
    if (index >= 0) {
      return itemsList[index];
    } else {
      throw NotFoundError('item not found'); // this creates a 404 response
    }
  }

  @PUT(url: "/<itemName>")
  Item updateItem(Item item, String itemName) {
    var index = itemsList.lastIndexWhere((element) => element.name == itemName);
    if (index >= 0) {
      itemsList[index] = item;
      return getItemByName(item.name ?? '');
    } else {
      throw NotFoundError('item not found'); // this creates a 404 response
    }
  }

  @POST(url: "/")
  Response createNewItem(Item item) {
    var index =
        itemsList.lastIndexWhere((element) => element.name == item.name);
    if (index == -1) {
      itemsList.add(item);
      return Response(201); // pass a shelf response
    } else {
      throw BadRequestError('item with name in list');
    }
  }

  // examplo of uploading a file
  @POST(url: '/upload')
  Future<RestResponse> upload(TestForm form) async {
    print(form);
    return new RestResponse(201, {"msj": 'ok'}, "application/json");
  }
}

Future<void> main(List<String> args) async {
  var router = Cascade();

  router = await mount(ItemsAdaptor(), router);

  var server = await io.serve(router.handler, _hostname, _port);
  print('Serving at http://${server.address.host}:${server.port}');
}

/* 
-------------------------------------
mounting Instance of 'ItemsAdaptor'
adding get to-do/list
adding get to-do/list/<iteName>
adding put to-do/list/<iteName>
adding post to-do/list/
adding post to-do/list/upload
-------------------------------------
Serving at http://localhost:8080
*/

Contributing

We welcome contributions to Annotation Shelf! If you have an idea for a new feature or have found a bug, please open an issue on GitHub.

License

Annotation Shelf is released under the BSD-3-Clause. See LICENSE for details.

thanks

Special thanks to the Shelf project team for providing us with the opportunity to create servers using this beautiful language.

श्रेणियाँ

निर्भरताएँ

निर्भरता सूची 3 आइटम

सोर्स रिपॉज़िटरी

इस पैकेज का उपयोग करने वाले प्रोजेक्ट

अभी कोई डेटा उपलब्ध नहीं है।