BaseHTTPClient: better constructor API, Default#1517
Conversation
to enable - connecting to alternative servers, either production or test mocks - unauthenticated calls, either for the initial auth or test mocsk
d43ff6b to
7659dea
Compare
| /// ``` | ||
| pub struct BaseHTTPClient { | ||
| client: Client, | ||
| pub client: reqwest::Client, |
There was a problem hiding this comment.
There was a problem hiding this comment.
It enables me constructing a mock client like this:
let mock_client = BaseHTTPClient {
base_url: mock_url,
..Default::default()
};I chose this way because I did not want to come up with a special name for it.
Alternatively we can make it private again, remove the Default trait and make a set of specialized constructors, like new_unauthenticated_with_url here?
There was a problem hiding this comment.
Anyway, I consider BaseHTTPClient pretty volatile, subject to quick rewrite as its users need it
There was a problem hiding this comment.
I was playing with an idea to implement some traits here and than do necessary changes in behavior in uderlying structs (which can even cover differences in using authorization token or not)
| /// A `default` client | ||
| /// - is NOT authenticated (maybe you want to call `new` instead) | ||
| /// - uses `localhost` | ||
| fn default() -> Self { |
There was a problem hiding this comment.
In my POV default (or bare in my PR) are the best names ...
... I was thinking about something like new -> authorized and default / bare -> nonauthorized or something more fancy with similar meaning. Simply because behavior of new is not that clear (that it expects authorization token somewhere already)
and renaming the helper authenticator
Prepare for releasing Agama 10· * #1263 * #1330 * #1407 * #1408 * #1410 * #1411 * #1412 * #1416 * #1417 * #1419 * #1420 * #1421 * #1422 * #1423 * #1424 * #1425 * #1428 * #1429 * #1430 * #1431 * #1432 * #1433 * #1436 * #1437 * #1438 * #1439 * #1440 * #1441 * #1443 * #1444 * #1445 * #1449 * #1450 * #1451 * #1452 * #1453 * #1454 * #1455 * #1456 * #1457 * #1459 * #1460 * #1462 * #1464 * #1465 * #1466 * #1467 * #1468 * #1469 * #1470 * #1471 * #1472 * #1473 * #1475 * #1476 * #1477 * #1478 * #1479 * #1480 * #1481 * #1482 * #1483 * #1484 * #1485 * #1486 * #1487 * #1488 * #1489 * #1491 * #1492 * #1493 * #1494 * #1496 * #1497 * #1498 * #1499 * #1500 * #1501 * #1502 * #1503 * #1504 * #1505 * #1506 * #1507 * #1508 * #1510 * #1511 * #1512 * #1513 * #1514 * #1515 * #1516 * #1517 * #1518 * #1519 * #1520 * #1522 * #1523 * #1524 * #1525 * #1526 * #1527 * #1528 * #1529 * #1530 * #1531 * #1532 * #1533 * #1534 * #1535 * #1536 * #1537 * #1540 * #1541 * #1543 * #1544 * #1545 * #1546 * #1547 * #1548 * #1549 * #1550 * #1552 * #1553 * #1554 * #1555 * #1556 * #1557 * #1558 * #1559 * #1560 * #1562 * #1563 * #1565 * #1566 * #1567 * #1568 * #1569 * #1570 * #1571 * #1572 * #1573 * #1574 * #1575 * #1576 * #1577 * #1578 * #1579 * #1580 * #1581 * #1583 * #1584 * #1585 * #1586 * #1587 * #1588 * #1589 * #1590 * #1591 * #1592 * #1593 * #1596 * #1597 * #1598 * #1600 * #1602 * #1605 * #1606 * #1607 * #1608 * #1610 * #1611 * #1612 * #1613 * #1614 * #1619 * #1620 * #1621
to enable
This is needed for both #1438 and #1495
In the end, the API changes only by adding a
Defaulttrait implementation which does no authentication.Connecting to a mock server is achieved by assigning to the public
base_urlfield.